[comp.std.c] 'sizeof' in preprocessing.

eyal@echo.canberra.edu.au (Eyal Lebedinsky) (10/06/90)

In article <12672@ogicse.ogi.edu> daniels@ogicse.ogi.edu (Scott David Daniels) writes:
[...]
>point that the committee's position is on a very slippery slope.  Since 
>sizeof cannot be used to control preprocessing, I don't see where any 
Reading the standard, any 'constant-expression' is valid for #if, and sizeof
is yielding a constant. So, one should be able to say:
#if sizeof (a) == 2
etc. I read it a while ago and though it too bad my compiler won't do this.
No separate cpp will do it (unless it learns some C).
Comments? I was reading 3.8.1 7/88 draft.


-- 
Regards
	Eyal

henry@zoo.toronto.edu (Henry Spencer) (10/07/90)

In article <1990Oct6.092032.345@csc.canberra.edu.au> eyal@echo.canberra.edu.au (Eyal Lebedinsky) writes:
>Reading the standard, any 'constant-expression' is valid for #if, and sizeof
>is yielding a constant...
>No separate cpp will do it (unless it learns some C).
>Comments? I was reading 3.8.1 7/88 draft.

You've either missed something or your draft is simply too far out of date.
(I can't remember what this looked like in 7/88.)  A very subtle point of
the interpretation of #if expressions is that keywords are not recognized
at all, so there is no way to write a sizeof.  This is specifically there to
permit separate preprocessors.
-- 
Imagine life with OS/360 the standard  | Henry Spencer at U of Toronto Zoology
operating system.  Now think about X.  |  henry@zoo.toronto.edu   utzoo!henry

browns@iccgcc.decnet.ab.com (Stan Brown, Oak Road Systems) (10/08/90)

In article <1990Oct6.092032.345@csc.canberra.edu.au>, eyal@echo.canberra.edu.au (Eyal Lebedinsky) writes:

> Reading the standard, any 'constant-expression' is valid for #if, and sizeof
> is yielding a constant. So, one should be able to say:
> #if sizeof (a) == 2
> etc. I read it a while ago and though it too bad my compiler won't do this.
> No separate cpp will do it (unless it learns some C).
> Comments? I was reading 3.8.1 7/88 draft.
 
I thing the preprocessor doesn't know C--specifically, the preprocessor
doesn't know your variable names.  For example, the following should be
a strictly conforming program and should compile successfully, assuming
"mumble" occurs nowhere else in the compilation:

    int mumble;
    #ifdef mumble
    #     error  The C preprocessor goofed
    #else
          /* This is the way it's supposed to work. */
    #endif

The above opinions are not attributable to any other person or company.
                                     email: browns@iccgcc.decnet.ab.com
Stan Brown, Oak Road Systems, Cleveland, Ohio, U.S.A.   +1 216 371 0043