[comp.std.c] typedef/old-style argument conflict question

ok@cs.mu.oz.au (Richard O'Keefe) (10/07/89)

I have a program where, because of its development over the years,
the following pattern occurred:

    /* in an included header file */
    typedef char *str;

    /* elsewhere */
    void make_table(len, str)
        int len;
        char *str;

I first discovered this when GCC complained about a syntax error near "str".
I don't want to defend the practice of using typedef names as arguments; it
really wasn't intentional.  My question is simply whether this code is
legal in the current ANSI draft.

henry@utzoo.uucp (Henry Spencer) (10/08/89)

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