J
James Kuyper
Tim said:Why? It must be an integer (or convert to an integer) in order for
it to be a valid return from main. And integers can be converted
to pointers in an implementation defined way.
Section 6.5.4p3: "Conversions that involve pointers, other than where
permitted by the constraints of 6.5.16.1, shall be specified by means of
an explicit cast." If EXIT_SUCCESS has a value of 0, then it counts as a
null pointer constant, which is permitted by 6.5.16.1. Otherwise, the
absence of an explicit cast is indeed a constraint violation.
Even if you change the code to use an explicit cast, one remaining
potential problem applies. Per section 6.3.2.3p6: "... 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."
Per footnote 41, a trap representation can be stored in 'q', but any
attempt to actually use the value of 'q' has undefined behavior.
Footnotes aren't normative, but this one correctly summarizes the
consequences of normative text in the standard.