Why 'struct foo *x' instead of 'foo *x'
Andrew Koenig
ark at alice.UUCP
Mon May 29 13:32:17 AEST 1989
In article <878 at m3.mfci.UUCP>, karzes at mfci.UUCP (Tom Karzes) writes:
> In article <9137 at csli.Stanford.EDU> jkl at csli.stanford.edu (John Kallen) writes:
> >
> >Does anybody know the reason why structs are defined as they are in C?
> >I.e. why do I have to say "struct foo" instead of just the tag "foo"?
> I think one reason is that it allows pointers to foo before foo itself is
> actually defined. For example:
> struct foo {
> struct bar *pb;
> };
> struct bar {
> struct foo *pf;
> };
You can say `foo' instead of `struct foo' in C++.
It handles the forward reference problem in one of two ways.
One is to allow `struct foo' as a type name even if `foo' has
not yet been defined. That makes the example above legal.
The other way is to allow the existence of a type name
to be established before the definition in some circumstances:
struct bar;
struct foo {
bar *pb;
};
struct bar {
foo *pf;
};
--
--Andrew Koenig
ark at europa.att.com
More information about the Comp.lang.c
mailing list