Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!wuarchive!uwm.edu!uakari.primate.wisc.edu!brutus.cs.uiuc.edu!husc6!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.std.c Subject: Re: "expandable" structs with last element declared using [1] Summary: rebuttals Message-ID: <15500@haddock.ima.isc.com> Date: 21 Dec 89 17:12:25 GMT Expires: 11 Jan 90 17:12:24 GMT References: <463@cpsolv.UUCP> <477@longway.TIC.COM> <468@bbxsda.UUCP> <4379@cuuxb.ATT.COM> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Distribution: comp.std.c Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 41 In article <468@bbxsda.UUCP> scott@bbxsda.UUCP (Scott Amspoker) writes: >...I see no way you would get screwed unless sizeof(char) is more than 1... >Maybe someone thinks that structure fields need not be allocated in any >particular order. In ANSI C, sizeof(char) must be 1 and structure members are allocated in the order that they're declared. But even among people who realize this, there is disagreement as to the legality of the construct in question. In article <4171@scolex.sco.COM> seanf@sco.COM (Sean Fagan) writes: >[Symbolic debugging information...] Now, imagine an architecture that does >that in hardware (well, microcode, probably). Guess what, there *are* >machines that do! ... Turning on bounds-checking in your compiler, if it >supported it, would cause it to fail. This doesn't prove that the construct is illegal. An equally valid interpretation is that implementations that like to do bounds-checking must settle for a weaker check in these cases, if they claim to be ANSI-conforming. In article <4379@cuuxb.ATT.COM> mmengel@cuuxb.UUCP (Marc W. Mengel) writes: >Gee guys, you *told* the compiler that foo->baz only has one character in it; >of *course* it's wrong to reference foo->baz[1]. Intuition is not necessarily a good guide to understanding the pANS. >Sooner or later you will find a machine with really wierd base/offset >limitations, and a compiler will try to generate > mov.b $1,8(%a2) >when the offset "n" on a "n(%am)" can only be 0..7, and you'll be sorry. The >compiler will have been correct in it's code generation because it "knew" >that the subscript had to be zero. That's a valid argument for why it *should* be illegal, but again, it doesn't make it so. If the construct *is* legal, then a compiler such as you describe is not ANSI-conforming, and hence is of little interest in this discussion. (Note: in this article I have responded to the arguments of the three previous posters, but have not supplied any evidence that would actually help answer the question. I'll do that in a separate posting.) Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint