Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!ukc!dcl-cs!aber-cs!pcg From: pcg@aber-cs.UUCP (Piercarlo Grandi) Newsgroups: comp.lang.c++ Subject: Re: g++ core dump from improper use of extern "C" Summary: Ansi C is like C++, now, as to forward declarations of types... Message-ID: <1587@aber-cs.UUCP> Date: 16 Jan 90 18:59:16 GMT Reply-To: pcg@cs.aber.ac.uk (Piercarlo Grandi) Organization: Dept of CS, UCW Aberystwyth (Disclaimer: my statements are purely personal) Lines: 61 I wrote: typedef short t; static struct a {struct b *b; long l[1];} a; main() { { auto t t1; typedef double t; auto t t2; printf(" size t1 %u, size t2 %u\n",sizeof t1, sizeof t2); } { struct a; struct c {struct a *a; long l[2];} c; struct a {struct c *c; long l[3];} a; printf(" size a %u, size c %u, size c.a %u\n", sizeof a, sizeof c, sizeof *(c.a)); } return 0; } This should print, on your typical 32 bit byte oriented machine, something like 8 and 2 on the first line and 16, 12, 8 on the second line. NOTE: it will fail to compile on some ancient C compilers that erroneously handle a typedef like a #define, e.g. Sun's. [ .... ] By the way, try it taking out the line 'struct a;'. It has pointed out to me (a few pieces of Hate Mail :->) that in Ansi C (which I love a lot :->) now 'struct b' *is* a forward declaration, just like in C++. Special casing is still strong; this means that On the other hand, of the (few: G++, Sun, Gould, Mips) compilers that I have tried, *none* could handle correctly the above code save for G++; they all chickened out at the redefinition of 't', save for one that allows for type 'short double' apparently... G++, meritoriously, handled the above monstrosity with flair, even issuing the most appropriate warnings, and printing 16, 2, 16 on the second line. What's amusing is that the presence of the 'struct a;' line does not seem to affect it. I think its absence should: as far as I know, the only (regrettable) exception to the one-pass-rule in C++ is class members, where in a member you can refer to members declared later. -- 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