Another sizeof question
Stephen Clamage
steve at taumet.com
Mon Oct 29 04:05:51 AEST 1990
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.
In ANSI C, sizeof may not usefully appear in an #if because it is part
of a different phase of translation. The preprocessor knows nothing
about types or variables, and sizeof is not a preprocessor keyword.
The preprocessor must treat "sizeof" as it does any undefined macro name.
Some C compilers support sizeof in the preprocessor. The results are
then kind of weird. Such preprocessors sometimes recognize the size of
the built-in types (int, long, etc), but not user types. Recognizing
the size of user types is part of the C compilation process, not just
preprocessing, so a stand-alone preprocessor must either act as a
complete C parser, or act differently than when it is part of the
complete compilation.
--
Steve Clamage, TauMetric Corp, steve at taumet.com
More information about the Comp.std.c
mailing list