Why are typedef names in the same name space as variable names?
Gregory Smith
greg at utcsri.UUCP
Thu Nov 27 05:23:18 AEST 1986
In article <4647 at ism780c.UUCP> tim at 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...
More information about the Comp.lang.c
mailing list