Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!udel!mmdf From: lawsonse@vttcf.cc.vt.edu (Shannon Lawson) Newsgroups: comp.sys.amiga.programmer Subject: Re: Is this valid C? Message-ID: <53200@nigel.ee.udel.edu> Date: 10 May 91 12:58:51 GMT Sender: mmdf@ee.udel.edu Lines: 35 > > 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. ALWAYS make sure your pointers point to something valid! > > - 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 -- Shannon Lawson || Virginia Polytechnic Institute Graduate Student || & State University Harry Lynde Bradley Department of || Electrical Engineering || E-Mail: lawsons@csgrad.cs.vt.edu Disclaimer: If I put my foot in my mouth, I can hardly hold someone else responsible, now can I?