Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: comp.lang.c Subject: Re: Why are typedef names in the same name space as variable names? Message-ID: <3692@utcsri.UUCP> Date: Wed, 26-Nov-86 14:23:18 EST Article-I.D.: utcsri.3692 Posted: Wed Nov 26 14:23:18 1986 Date-Received: Wed, 26-Nov-86 17:27:50 EST References: <1092@spice.cs.cmu.edu> <307@cartan.Berkeley.EDU> <3644@utcsri.UUCP> <4647@ism780c.UUCP> Reply-To: greg@utcsri.UUCP (Gregory Smith) Distribution: net Organization: CSRI, University of Toronto Lines: 40 Summary: In article <4647@ism780c.UUCP> tim@ism780c.UUCP (Tim Smith) writes: >There is already a problem with telling when the declarations end. >Consider this program: > > main() { > a; /* declare an integer variable */ > a = 1; /* put something in it */ > } > >Every C compiler I have tried complains about an undeclared variable on >line 2. If "a" is a global, they have no problem: > > a; > main() { > a = 1; > } In the first example, line 2, 'a;' is a statement, to wit, the expression 'a'. It is an error only because there is no 'a' in scope. Declarations inside blocks must specify a type or a storage class. I am not saying that this is perfectly consistent; however it is thoroughly documented. In fact any C compiler that doesn't complain about the first example must be broken in a nasty way. Given this rule, there is no ambiguity in determining whether a thing in a block is another declaration or the first statement. If it starts with a type/storage-class specifier keyword, it is a declaration. If it starts with a currently defined typedef identifier, it is also a declaration. Anything else is either a statement or a syntax error. Do you expect to be able to declare the external function foobar as below? func(){ foobar(); /* declare ext. function foobar */ foobar(); /* call it */ } -- ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg Have vAX, will hack...