Newsgroups: comp.std.c
Path: utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: typedef/old-style argument conflict question
Message-ID: <1989Oct7.223731.7388@utzoo.uucp>
Organization: U of Toronto Zoology
References: <2324@munnari.oz.au>
Date: Sat, 7 Oct 89 22:37:31 GMT

In article <2324@munnari.oz.au> ok@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@zoo.toronto.edu
