Good point, I misremembered that. I have read the standard, but it seems that they changed some of the language around between C17 and C23. In C17 (6.3.2.3 Pointers), we have:
> 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.68)
> 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 in C23 (6.3.2.3):
> 5 An integer may be converted to any pointer type. Except as previously specified, the result is implementation-defined, may not be correctly aligned, may not point to an entity of the referenced type, and can produce an indeterminate representation when stored into an object.58)
> 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 is not required to be in the range of values of any integer type.
It's interesting that they dropped the "trap representation" language from C23. Of course, being an "indeterminate representation" probably does the same thing given that "trap representation" isn't a thing in C23 at all.
But yeah, I was wrong about the pointer roundtrip.
> 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.68)
> 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 in C23 (6.3.2.3):
> 5 An integer may be converted to any pointer type. Except as previously specified, the result is implementation-defined, may not be correctly aligned, may not point to an entity of the referenced type, and can produce an indeterminate representation when stored into an object.58)
> 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 is not required to be in the range of values of any integer type.
It's interesting that they dropped the "trap representation" language from C23. Of course, being an "indeterminate representation" probably does the same thing given that "trap representation" isn't a thing in C23 at all.
But yeah, I was wrong about the pointer roundtrip.