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: <635@lysator.liu.se> Date: 16 May 91 05:35:48 GMT References: <53200@nigel.ee.udel.edu> <38763@ditka.Chicago.COM> Sender: news@isy.liu.se (Lord of the News) Organization: Lysator Computer Club, Linkoping University, Sweden Lines: 64 comeau@ditka.Chicago.COM (Greg Comeau) writes: >In article <53200@nigel.ee.udel.edu> lawsonse@vttcf.cc.vt.edu (Shannon Lawson) writes: >>> In article <616@lysator.liu.se> zap@lysator.liu.se (Zap Andersson) writes: >>> >struct foop *p; struct foop { int a; char *b }; >>> > >main() { p->a = 39; /* Will complier barf here? */ } >>> > There will be a no barf since at the ->a, foop is no longer an incomplete >>> > type. It is not a problem. >>I disagree. p is a pointer to foop, and has not been allocated a foop to which >>it may point. Depending on the compiler, p points to some random location, so >>you are happily sticking the value 39 into some nebulous area. Although your >>syntax is correct (and the compiler may not gag), you should see a problem >>at runtime when you try to reference p. >Please do not compare apples to oranges. >The original posting dealt strictly wiht the accessibility of p/a and >hence it was answered in that context. Yes, and I don't know how it got there since I wrote it - and I had TWO pices of code in it. In ONE of them I explicitly wrote malloc(sizeof(foo)) just to SHOW people that that wasn't the point. I seem to have forgottn that in the last example - sorry - but that was NOT the point at ALL, ok? The point was: If you say: struct kevlar_oysters *ipp; /* Wich is valid EVEN IF kevlar_oysters are un- known as this time: ipp is a pointer to an 'unknown' structure */ and AFTER that you do: struct kevlar_oysters { int foo; float bar; }; Now the structure TYPE itself is known - however, is a compiler sufficiently intellegent to know that it's previously marked as 'pointer to unknown structure' is suddenly a KNOWN structore? I dont know, I think it is compiler dependant. So if I NOW do ipp = calloc(39,sizeof(struct kevlar_oysters)); /* To keep you happy :-) */ if (ipp) /* To keep you EVEN HAPPIER B-] */ ipp->bar = 39; The POINT is, will the COMPILER barf here, period. I dont care if the program kills memory - I won't RUN it, I will just use it as a nice exercise for my compiler (up - and stretch - and down - and relax) >Re the runtime issues (not the original compile time issues), what you >describe is most certainly true given the way the code snipet above is >composed. Agreement is utter and total. The code is never run - just compiled. Hep! >- Greg >-- > Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418 > Producers of Comeau C++ 2.1 > Here:attmail.com!csanta!comeau / BIX:comeau / CIS:72331,3421 > Voice:718-945-0009 / Fax:718-441-2310 -- * * * * * * * * * * * * * * * * * (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)