Interview Question
Country: United States
A conforming implementation shall produce at least one diagnostic message for a violation of any syntax rule or constraint.
Disagree.
Constraints - syntactic and semantic restrictions by which the exposition of language elements is to be interpreted.
Undefined behavior - behavior, upon use of a nonportable or erroneous program construct, of erroneous data, or of indeterminately valued objecs, for which the standard imposes no requirements.
If a "shall" or "shall not" requirement that appears outside of a constraint is violated, the behavior is undefined. Undefined behavior is otherwise indicated in this standard by the words "undefined behavior" or by the omission of any explicit definition of behavior.
This is clearly a constraints violation not undefined behavior.
"The sizeof Operator
Constraints
The sizeof operator shall not be applied to an expression that has function type...
Semantics
The sizeof operator yields the size (in bytes)..."
That is verbatim from the Standard.
Also from the Standard: "An implementation may also successfully translate an invalid program."
But as previously stated a compliant compiler shall emit a diagnostic message.
From the Standard: "The sizeof operator shall not be applied to an expression that has function type ...".
- Anonymous September 02, 2012Hence the above code is not valid C code and should not compile.