Another sizeof question

Doug Gwyn gwyn at smoke.brl.mil
Mon Oct 29 11:50:07 AEST 1990


In article <13171 at crdgw1.crd.ge.com> volpe at camelback.crd.ge.com (Christopher R Volpe) writes:
>Can someone tell me whether "sizeof" expressions are allowed as 
>operands of "#if"? I'm trying to do some conditional compilation
>based on the size of some data structure, and I get parse errors
>before sizeof. The Bible says "sizeof" yields a constant integer,
>and that #if requires an integral constant expression, so I can't
>tell what's wrong. Can someone clue me in? Thanks.

While the identifier "sizeof" may be used in the integral constant
expression controlling conditional inclusion (i.e. operand of #if),
you need to be aware that this stuff occurs during translation phase
4, involving preprocessing tokens, not "pure C language" tokens.
Thus, language keywords (such as "sizeof") have no special meaning;
identifiers are macro-substituted and any that had no substitutions
are then replaced with "0".  It is the result of that substitution
that is evaluated for the constant expression.  Thus, there can be no
enumeration constants, types, and so forth involved in the condition.



More information about the Comp.std.c mailing list