Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!styx!mordor!sri-spam!sri-unix!hplabs!ucbvax!cartan!brahms!ballou From: ballou@brahms (Kenneth R. Ballou) Newsgroups: comp.lang.c Subject: Re: Why are typedef names in the same name space as variable names? Message-ID: <307@cartan.Berkeley.EDU> Date: Sat, 15-Nov-86 18:50:11 EST Article-I.D.: cartan.307 Posted: Sat Nov 15 18:50:11 1986 Date-Received: Sun, 16-Nov-86 02:25:13 EST References: <1092@spice.cs.cmu.edu> Sender: daemon@cartan.Berkeley.EDU Reply-To: ballou@brahms (Kenneth R. Ballou) Distribution: net Organization: Math Dept. UC Berkeley Lines: 33 In article <1092@spice.cs.cmu.edu> jgm@spice.cs.cmu.edu (John Myers) writes: >In article <4220@ut-ngp.UUCP> dlnash@ut-ngp.UUCP (Donald L. Nash) writes: >>Why are typedef names in the same name space as variable names?... > >If they weren't, then what would the output of the following program be? > >#include >main() >{ > typedef car foo; Is this a typo, and supposed to be typedef char 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). If, however, you were to write sizeof foo , you would then get the size of a long integer on your machine. References: K&R: page 126 (explains sizeof (object) and also points out that sizes are given in unspecified units called "bytes," which are the same size as a char); page 187 (gives two forms of the *operator* sizeof, namely sizeof expression and sizeof (type-name) ); page 188 (defines the meaning of the constructs involving sizeof and also notes that "byte" is the space required to hold a char *in all existing implementations*). -------- Kenneth R. Ballou ...!ucbvax!brahms!ballou Department of Mathematics ballou@brahms.berkeley.edu University of California Berkeley, California 94720