Why are typedef names in the same name space as variable names?

Joseph S. D. Yao jsdy at hadron.UUCP
Mon Nov 24 08:22:23 AEST 1986


In article <307 at cartan.Berkeley.EDU> ballou at brahms (Kenneth R. Ballou) writes:
>In article <1092 at spice.cs.cmu.edu> jgm at spice.cs.cmu.edu (John Myers) writes:
>>In article <4220 at ut-ngp.UUCP> dlnash at ut-ngp.UUCP (Donald L. Nash) writes:
>>>Why are typedef names in the same name space as variable names?...
>>#include <stdio.h>
>>main()
>>{
>>    typedef car foo;
>>    long foo;
>>    printf("%d\n",sizeof(foo));
>>}
>I don't see that there is a question here.  Sizeof is *NOT* a function, as was
>quite thoroughly discussed some time back in this group.  Note that (foo) in
>this case is the syntax of a type cast, and in this case, sizeof returns 
>the size of a datum of type foo (in this case, 1).

(foo) is also an expression.  If the typedef were not present, this
would still be a legal C program, with an unambiguous compilation:
the size of the long int "foo" would be printed out.  As it is, I
believe either interpretation is "correct".

Thus, purely BTW, this can be considered a bad program -- I think
it's not a good idea to use a name for more than one purpose, when
a less ambiguous way of doing the same thing can be found.

As I mentioned before, to keep people honest and as MY OWN PERSONAL
preference of style, I use the parentheses in both cases.  (Emphasis
mine, not zippy's or root boy's -- don't flame if it's just not your
own personal style.)
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}
			jsdy at hadron.COM (not yet domainised)



More information about the Comp.lang.c mailing list