Can anybody tell me how to make this C code work in C++ please?
uint64_t flv_dbl2int( double value )
{
return (union {double f; uint64_t i;}){value}.i;
}
I’m not precisely sure what is going on, is it bit shift?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As far as I can tell, the only legal strategy for type punning in C++ is through
memcpy(), ieThe straight-forward solution using
reinterpret_castis actually undefined behaviour, same as using C-style pointer casts.
Using unions (as the original solution does), while legal in C, is probably illegal in C++. In practice, all of these solutions are likely to work, and at least gcc-4.5.3 and clang-3.0 will produce identical code on x86 at
-O1.