Another sizeof question

Henry Spencer henry at zoo.toronto.edu
Mon Oct 29 09:37:02 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"? ...

In ANSI C, no, they are not.  Preprocessing is done before there is any
notion of declarations, types, storage layout, or sizes.  In a #if, `sizeof'
is just another identifier.

>...The Bible says "sizeof" yields a constant integer,
>and that #if requires an integral constant expression, so I can't
>tell what's wrong...

It's not clear which Bible you are reading. :-)  Is it the Old Testament
(K&R1), the New Testament (K&R2), or the New American Edition (ANSI)?
In a sufficiently modern and complete edition, you will find the rule
against this down in the fine print.

>BTW, I'm using gcc to compile.

Note that GNU C and standard C are only somewhat related.
-- 
"I don't *want* to be normal!"         | Henry Spencer at U of Toronto Zoology
"Not to worry."                        |  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.std.c mailing list