Path: utzoo!attcan!uunet!aplcen!samsung!zaphod.mps.ohio-state.edu!uwm.edu!uwvax!umn-d-ub!umn-cs!mike From: mike@umn-cs.CS.UMN.EDU (Mike Haertel) Newsgroups: comp.lang.c++ Subject: Re: g++ core dump from improper use of extern "C" Message-ID: <18157@umn-cs.CS.UMN.EDU> Date: 12 Jan 90 18:31:50 GMT References: <1581@aber-cs.UUCP> Reply-To: mike@umn-cs.cs.umn.edu (Mike Haertel) Organization: Free Software Foundation Lines: 33 In article <1581@aber-cs.UUCP> pcg@cs.aber.ac.uk (Piercarlo Grandi) writes: >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. Just to be pedantic, this is not strictly true. It is OK to declare a pointer to an incomplete type, so this works *here*. But consider the following counterexample: /*1*/ struct b { int x; }; /*2*/ /*3*/ void foo() { /*4*/ struct b; /*5*/ struct a { struct b *b; } *a; /*6*/ struct b { struct a *a; } *b; /*7*/ /*8*/ b = a->b; /*9*/ } In this case, line 4 is necessary to make "struct b" an incomplete type. Otherwise, the "struct b *b" in line 5 would refer to the "struct b" declared on line 1, and line 8 would be a pointer type mismatch. The moral of the story is to declare all your types at file scope. -- Mike Haertel "Everything there is to know about playing the piano can be taught in half an hour, I'm convinced of it." -- Glenn Gould