typedef/old-style argument conflict question
Henry Spencer
henry at utzoo.uucp
Sun Oct 8 08:37:31 AEST 1989
In article <2324 at munnari.oz.au> ok at cs.mu.oz.au (Richard O'Keefe) writes:
> typedef char *str;
> void make_table(len, str)
> int len;
> char *str;
>... wasn't intentional. My question is simply whether this code is
>legal in the current ANSI draft.
No. Declaring a parameter with the same name as a typedef is specifically
forbidden. The problem is that there are two forms of parameter lists in
ANSI C: the old `void make_table(len, str)' followed by declarations, and
`void make_table(int len, char *str)' which is self-contained. C is fun
to parse anyway, but it's *very* hard to tell the difference between these
two if redeclaration of typedef names as parameters is legal... especially
since a function declaration (as opposed to a definition, which has a body)
can use the second form but omit parameter names! And until you see what
follows the parameter list, you don't know whether you're dealing with a
declaration or a definition. Especially when you start thinking about
syntax-error recovery, this whole area is a terrible mess, and forbidding
redeclaration of typedef names is a considerable blessing.
--
Nature is blind; Man is merely | Henry Spencer at U of Toronto Zoology
shortsighted (and improving). | uunet!attcan!utzoo!henry henry at zoo.toronto.edu
More information about the Comp.std.c
mailing list