|
|
|
|
|
by boomlinde
2928 days ago
|
|
They are optional, but only in the sense that if you can't exactly represent e.g. uint64_t, there can't be a uint64_t type. So the example above is kosher in the sense that it's standards compliant, even if it isn't perfectly portable (for reasons unrelated to memset type punning; that you're using uint64_t in the first place). If an implementation can't represent uint64_t exactly, it can still have a uint_least64_t type of whatever width works. |
|
a) I believe sizeof (double) * 8 == 64 is not enforced by the standard either. One could argue that it is hard to find anything else these days, but (for a contrived example) I believe nothing prevents you from making your own port of GCC for some purpose, and make 'double' be 'float'. (From my memories, it is even far enough from rocket science.)
b) It already happened to me personally, to work with code where people have implemented their own uintXX types (because of the lack of the standard ones), and then over time these became narrower/vider.
So if we would like to have it portable, I think, nothing beats:
union { double d; char cc [sizeof (double)]; };
and there we are, back to what is in the standard.