Xref: utzoo gnu.g++.bug:1319 comp.lang.c++:6111 Path: utzoo!attcan!uunet!mcsun!ukc!dcl-cs!aber-cs!pcg From: pcg@aber-cs.UUCP (Piercarlo Grandi) Newsgroups: gnu.g++.bug,comp.lang.c++ Subject: Re: g++ core dump from improper use of extern "C" Summary: "struct a;" has never been necessary. Message-ID: <1581@aber-cs.UUCP> Date: 11 Jan 90 17:56:11 GMT Reply-To: pcg@cs.aber.ac.uk (Piercarlo Grandi) Organization: Dept of CS, UCW Aberystwyth (Disclaimer: my statements are purely personal) Lines: 62 In article <494@ucl-cs.UUCP> T.Day@ucl-cs.UUCP writes: From: Tim Day Piercarlo "Peter" Grandi writes: > using 'struct some *' before having seen 'struct some {...' > is legal and without problem in both C and C++ Not quite. You have to say struct frob; before you can use pointers or references to frob. Not really, neither in C nor in C++. Try compiling: struct a {struct b *b;} a; struct b {struct a *a;} b; It shall work, both in C and C++. There has never been a requirement that the name of a struct be known before its use, if its use is to declare a pointer to the struct. The compiler need not bother; anything that comes after 'struct' must be a struct name, and a pointer has always the same size. You are confusing this point with the the fact that in C++, saying 'struct a;', which in it as well as in C++ is an empty declaration, and no special construct all, also has the effect of typedef'ing 'a' as 'struct a'. The compiler needs to know that a name is a typedef, otherwise parsing declarations cannot be done. In this, the C++ practice of saying 'class c;' is NOT a forward declaration; it i just the old harmless practice of having empty declarations, coupled with the new side effect of having an implicit typedef. Saying beforehand 'class c;' in C++ is not needed if you write 'class c *m;' instead of 'c *m;'. The effect is the same if you just say 'typedef class a ;'. With the following preprocessor macro you get the same effect in C: #define mode(FLAVOR,NAME) \ typedef FLAVOR NAME NAME; FLAVOR NAME Note that the typedef appears *before* the struct definition, if any; if you follow this with a ';' the struct definition becomes a harmless empty delcaration. You can use this in C as mode(struct,complex) { float re,im; }; complex a,b,c; or mode(struct,clutch); mode(struct,car) { ...; clutch *theClutch; ... }; just like in C++, if you have got fed up with using leading 'struct', 'union', 'enum' (enums are special though in C)... -- Piercarlo "Peter" Grandi | ARPA: pcg%cs.aber.ac.uk@nsfnet-relay.ac.uk Dept of CS, UCW Aberystwyth | UUCP: ...!mcvax!ukc!aber-cs!pcg Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk