Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!aplcen!samsung!think!snorkelwacker!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] Message-ID: <15474@haddock.ima.isc.com> Date: 19 Dec 89 05:13:57 GMT References: <463@cpsolv.UUCP> <477@longway.TIC.COM> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 28 In article <477@longway.TIC.COM> uunet!sq!msb (Mark Brader) writes: >A second issue is whether the usage is in conformance with the proposed >ANSI Standard (pANS) for C. I claim that it is. My earlier posting on this topic attempted to prove it rigorously; Doug acknowledged that I'd proved the legality of strcpy(foo->baz, "x") but questioned whether explicitly referencing foo->baz[1] is legal. I claim that there is no difference: if it's illegal to reference foo->baz[1] directly, for whatever reason, then it cannot become legal simply by using an auxiliary variable to hide the reference. A tight-sphinctered implementation could try to, and should be able to, enforce the bounds-checking at all levels with run-time checks. Thus if foo->baz[1]='\0' is illegal, then so is char *temp = foo->baz; temp[1] = '\0'; and so is void hideaway(char *p) { p[1] = '\0'; } ... hideaway(foo->baz); and so is strcpy(foo->baz, "x"); (all of which are just variations on a theme). And thus contrapositively, the legality of the strcpy() implies the legality of the direct reference. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint (I don't expect this issue to be settled by anything less than an official Request for Interpretation, but this is my expert opinion.)