??? 08/27/08 08:07 Read: times |
#157786 - Programmer knowledge required. Responding to: ???'s previous message |
However, using a union in the manner of the other post is a quite common misuse of the language, the standard for which states:
It's quite sensible to declare this in the standard, since the results will be completely implementation-specific and the programmer has to _know_ what exactly he's doing there. However, the same is true for dereferencing the cast-to-address-of-float address of a long. The programmer has to know that the long variable actually contains data that makes sense if interpreted as an IEEE 754 float, and that the compiler actually uses IEEE 754 as its floating-point format. Conclusion: If you want to write highly-portable C code, then don't do that. In fact, if you _really_ want to write highly-portable C code, there is no way of doing this operation short of implementing your own IEEE 754 floating-point math, since you can't be sure that the compiler actually uses this format. |
Topic | Author | Date |
silly C question | 01/01/70 00:00 | |
*(float*)&time | 01/01/70 00:00 | |
Thanks!!! | 01/01/70 00:00 | |
Here's one without wild casting: | 01/01/70 00:00 | |
Nothing wild | 01/01/70 00:00 | |
union misuse | 01/01/70 00:00 | |
Not hiding cast | 01/01/70 00:00 | |
Programmer knowledge required. | 01/01/70 00:00 | |
Hiding of portability issue | 01/01/70 00:00 | |
Portability C | 01/01/70 00:00 |