"expandable" structs with last element declared using [1]

Karl Heuer karl at haddock.ima.isc.com
Tue Dec 19 16:13:57 AEST 1989


In article <477 at 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 at 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.)



More information about the Comp.std.c mailing list