Circular references in declerations

Karl Heuer karl at haddock.ima.isc.com
Thu Mar 1 07:50:17 AEST 1990


In article <677 at mwtech.UUCP> martin at mwtech.UUCP (Martin Weitzel) writes:
>By tradition (%), name spaces for struct- and union-tags (uy, sx)
>are separated from the name space for typedef-s (X, Y), so you
>could in fact write.
>	typedef union Y { ..... ; struct X *x; ..... } Y;
>	typedef struct X { ..... ; union Y *y; ..... } X;
>I don't know, if I should recommend to choose the same name
>as struct/union-tag *and* typedef-d name. If you fully understand
>the background, it saves remembering 'which is which', but for
>the 'non-gurus' it might obscure the facts.

>(%): C++ breaks with this tradition: A struct- or union-tag is
>*automatically* a type name.

It is for this reason that I *always* use the same name for the tag and the
typedef: it makes it more compatible with C++ usage.  If I ever want to
convert the declarations to C++, all I have to do is remove the explicit
typedef, since C++ provides it automatically.  And since it has been suggested
that C-2001 might be a standardization of C++ rather than C (though I hope
not), it seems useful to keep the code "close" to C++ when the cost is small.

Karl W. Z. Heuer (karl at ima.ima.isc.com or harvard!ima!karl), The Walking Lint



More information about the Comp.lang.c mailing list