Re:C++ by Example
by kazinator on Thursday September 22, 2022 @06:10PM
(#32945280)
The meaning of punning memory is obvious if you understand the implementation-specific representations being used. E.g. if you understand what a 64 bit double looks like and what a 64 bit integer looks like, then it makes sense when you look at the memory of one through the type of the other. The C or C++ program to it has only two rationally defensible meanings: "undefined behavior" (ISO C or C++ interpretation, allowing certain optimizations, or run-time diagnosis of a type mismatch or whatever) or else "do the obvious thing and access the bits like the code says". What the code is asking for can certainly be be framed in terms of concepts in the standard. Just what the code is obviously requesting is not granted by any requirements in the standard. The idea that by asking for it, it's not a C++ program any more is silly.
There is no standardized programming language that doesn't have vendor specific extensions comprising a local dialect.
There is no standardized programming language that doesn't have vendor specific extensions comprising a local dialect.