Thanks for the answers! > > Why? Won't the following work? > > > > void setNaN(float &v) { > > union { float f; int i; } t; > > t.i = 0x7f800001; > > v = t.f; > > } > > > 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.
Thinking about this setNaN trick, why is it not kosher? It seems completely OK to me (too bad that I missed this "trick"). Note that my problem is not the unnecessary type-punning warning (I could live with that), but miscompiled code because of the too strict rule that GCC uses. Maybe GCC shouldn't optimize around invalid type-punnings? Geza