Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!netnews.upenn.edu!eecae!shadooby!sharkey!mcf!mibte!gamma!thumper!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: Why 'struct foo *x' instead of 'foo *x' Message-ID: <9405@alice.UUCP> Date: 29 May 89 03:32:17 GMT References: <26575@watmath.waterloo.edu> <10213@claris.com> <878@m3.mfci.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 39 In article <878@m3.mfci.UUCP>, karzes@mfci.UUCP (Tom Karzes) writes: > In article <9137@csli.Stanford.EDU> jkl@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@europa.att.com