Can you count on a semi-modern processor being able to do floating-point calculations with a piece of data the same size as a pointer? Is there a defined type (possibly in a platform-specific header file) for such a type? I’m after the effect of intptr_t but for floats.
Edit:
I’m not referring to C’s float type, but to floating-point numbers in general.
Edit:
Do I need to just have a script run, testing what the sizes of float, double, and void * are for the compiler being used, and generate an appropriate header file to typedef a type that other code uses?
The closest you will get is:
On the down side, this is not exactly what you asked for. On the bright side, it is 100% standard…
[edit]
Yes, you could use
sizeofto compare your pointer size tofloat,double, andlong double, and pick one. But as @R. points out, many pointer values will map toNaN, so you will not be able to do anything with those floating point values other than cast them back to a pointer… And even that is not guaranteed to work (although it probably will in practice).But if you cannot do anything with the floating point value except cast it back to a pointer, then you are better off using a union, since that will be just as space-efficient and will actually work portably.