🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1893

Re: Another sizeof question

#1893
From: Stephen Clamage
Date: Sun, 28 Oct 1990 17:05
24 lines
1542 bytes
volpe@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@taumet.com
Technical Details
Message-ID: <492@taumet.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!taumet!steve
References: <13171@crdgw1.crd.ge.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!taumet!steve
From: steve@taumet.com (Stephen Clamage)
Newsgroups: comp.std.c
Subject: Re: Another sizeof question
Message-ID: <492@taumet.com>
Date: 28 Oct 90 17:05:51 GMT
References: <13171@crdgw1.crd.ge.com>
Organization: Taumetric Corporation, San Diego
Lines: 24