4 ms·
Actually, the behavior is a combination of undefined and implementation defined. To the extent that it's implementation defined, it may still result in nasal de
by nknight 14y ago
Actually, the behavior is a combination of undefined and implementation defined. To the extent that it's implementation defined, it may still result in nasal demons, but they have to be documented nasal demons.
Point is, it's strictly non-portable according to the standard, but when done carefully is unlikely to break on a general-purpose architecture.
This is from C99, I don't have a copy of C11:
6.3.2.3 Pointers
[...]
5) An integer may be converted to any pointer type. Except as previously specified, the result is implementation-defined, might not be correctly aligned, might not point to an entity of the referenced type, and might be a trap representation.[56])
6) Any pointer type may be converted to an integer type. Except as previously specified, the result is implementation-defined. If the result cannot be represented in the integer type, the behavior is undefined. The result need not be in the range of values of any integer type.
[...]
And footnote [56]: The mapping functions for converting a pointer to an integer or an integer to a pointer are intended to be consistent with the addressing structure of the execution environment.