recursive typedefs

Tom Karzes karzes at mfci.UUCP
Thu May 19 06:18:29 AEST 1988


In article <8805180221.AA15564 at jade.berkeley.edu> ERICMC at USU.BITNET (Eric McQueen) writes:
>) From: chris%MIMSY.UMD.EDU at UMD2.BITNET 12-MAY-1988 06:04
>)
>) My own feeling is that it should be legal.  The argument against
>) it is that it is not obvious what this means:
>)
>)       typedef int (*pfi)();
>)       typedef unsigned pfi upfi;
>)
>) and I believe that because of this argument, it is explicitly
>) illegal.  Certainly the `#define's are safer.
>)
>) Chris

I think it's extremely bad practice to try to "modify" typedef types as
if they were mere macros.  It's much better to simply create the set of
"machine" typedefs you need at the start, constructed from primitive data
types, rather than to try to modify them later.

Furthermore, trying to support this sort of thing causes problems in many
lexers/parsers, making it harder to support legal C in cases like the
following:

    typedef int     foo;

    double xxx()
    {
        double  foo;

        foo = 123.456;

        return foo;
    }

Try this on a pcc-based C compiler.  It's legal C, but it doesn't work on
most compilers, particularly those that allow unsigned to be applied to
typedef types, because they try to lex "foo" in the declaration in xxx as
if it were a type, rather than a symbol.  A reasonably debugged C compiler
will handle the above code.



More information about the Comp.lang.c mailing list