Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!sunic!liuida!isy!lysator.liu.se!zap From: zap@lysator.liu.se (Zap Andersson) Newsgroups: comp.sys.amiga.programmer Subject: Re: Is this valid C? Message-ID: <616@lysator.liu.se> Date: 6 May 91 08:57:38 GMT References: <1991May5.222328.16225@csis.dit.csiro.au> Sender: news@isy.liu.se (Lord of the News) Organization: Lysator Computer Club, Linkoping University, Sweden Lines: 57 dave@csis.dit.csiro.au (David Campbell) writes: >Is this valid C? >Its just that this will compile on my favourite Unix compiler but won't >on Lattice V5.10. >I wish G++ was around for the Amiga!!!!!! >It turns out that C++ (on my Sparc) spits out similar code (I'm using >C++ on the sun to develop programs for the Amiga). >/*--------------------------------------------------------------------------*/ >extern struct thing t; This is very invalid, since struct thing isn't defined yet. However the line extern struct thing *t; is valid, even though 'thing' isn't defined yet. >struct thing { > int n; > char *s; >}; >main() >{ > t.n = 10; > t.s = "hello"; >} >/*--------------------------------------------------------------------------*/ Question is how an access of the t->n and t->s would go, (if it was defined as a pointer, in my case) now? I.e: struct foop *p; struct foop { int a; char *b }; main() { p = malloc(...) p->a = 39; /* Will complier barf here? Since the contents of the structure 'foop' was defined AFTER the 'pointer to unknown structure' p was created? Hmmmm? */ } >-- Dave Campbell >-- dave@csis.dit.csiro.au >-- >dave campbell -- * * * * * * * * * * * * * * * * * (This rent for space) * My signature is smaller than * Be warned! The letter 'Z' is Copyright 1991 * yours! - zap@lysator.liu.se * by Zap Inc. So are the colors Red, Green and * * * * * * * * * * * * * * * * * Greenish-yellow (Blue was taken by IBM)