Undefined structures
Doug Gwyn
gwyn at smoke.brl.mil
Tue Feb 5 07:27:45 AEST 1991
In article <442 at newmedia.UUCP> jim at newmedia.UUCP (Jim Beveridge) writes:
>If I make the declaration, "struct junk *g;" after the extern above,
>it compiles correctly even though "struct junk" doesn't exist.
struct junk *g; declares that g is a pointer to a struct tagged "junk"
(that in this case has not yet had its members declared). This is one
instance of an "incomplete type". If the program is to make any use of
the type that requires a complete type, e.g. sizeof(*g), then there
must be another declaration that completes the type before it is used.
If the type is never needed for anything, it need not be completed.
There are two other loosely related points: The standard seems to say
that all structure/union/enum tags and typedef names used in prototype
parameter declarations have prototype scope, but I think that is not
the intention; rather if a declarator was included it is just the
identifier in the declarator portion that has prototype scope, not one
in the type-specifier portion. (This would be worth getting a formal
interpretation ruling on.) The other point is that all pointers to
struct turn out to have to have similar representations (at least so
many of us think), so a pointer to any kind of struct would be good
enough for the compiler and it may not notice that you never declare
what the particular kind you actually referred to actually looks like.
More information about the Comp.lang.c
mailing list