This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Herman Geza <hg211@hszk.bme.hu> writes:As far as I know, this is guaranteed to work with GCC. But it is not kosher according to language standards, so other compilers might dislike it. On the other hand, other compilers are not guaranteed to optimize the call to "memcpy" out either.
[...]
What is the correct way to do this:
void setNaN(float &v) { reinterpret_cast<int&>(v) = 0x7f800001; }
without a type-prunning warning? I cannot use the union trick here
Why? Won't the following work?
void setNaN(float &v) {
union { float f; int i; } t;
t.i = 0x7f800001;
v = t.f;
}
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |