Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!andrew.cmu.edu!jm36+ From: jm36+@andrew.cmu.edu (John Gardiner Myers) Newsgroups: comp.lang.c Subject: Re: Zero Length Arrays Allowed in C Standard? Message-ID: Date: 7 Dec 89 18:37:37 GMT References: <2298@jato.Jpl.Nasa.Gov> <11715@smoke.BRL.MIL> <480@codonics.COM> <1989Dec2.210042.12668@twwells.com> <8129@cg-atla.UUCP> <1989Dec5.112553.24087@twwells.com> <11963@phoenix.Princeton.EDU>, <11751@smoke.BRL.MIL> Organization: Mathematics, Carnegie Mellon, Pittsburgh, PA Lines: 41 In-Reply-To: <11751@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes: > In article <11963@phoenix.Princeton.EDU> tbrakitz@phoenix.Princeton.EDU (Triantaphyllos B\ > yron Rakitzis) writes: > -Bill Wells says: > ->... some systems might take that [1] declaration > ->seriously and give you an error when you access something beyond > ->the first element of the string. The kind that immediately comes > ->to mind is debugging interpreters: these, one hopes, will check > ->for accessing outside the bounds of an array. > -Wait, hold on a second. If an implementation of C does bounds checking > -then it isn't C any more. > > Wrong. [...] > Just because you aren't familiar with an implementation like Bill > described does not mean they don't exist or that they're not valid > C implementations. Ok, I'll bite. I claim that the following program is (modulo typos) strictly conforming. Could someone please point out which constraint I missed? #include main() { struct foo_struct { int bar; char baz[1]; } *foo; foo = (struct foo_struct *) malloc(sizeof(struct foo_struct)+1); foo->baz[1] = 1; /* error? */ return 0; } Note that it is provable that the char pointer (foo->baz + 1) points within the object returned by malloc. -- _.John G. Myers Internet: John.G.Myers@andrew.cmu.edu (412) 268-2984 LoseNet: ...!seismo!ihnp4!wiscvm.wisc.edu!give!up