Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!cg-atla!fredex From: fredex@cg-atla.UUCP (Fred Smith) Newsgroups: comp.lang.c Subject: Re: Zero Length Arrays Allowed in C Standard? Message-ID: <8141@cg-atla.UUCP> Date: 6 Dec 89 14:32:48 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> Reply-To: fredex@cg-atla.UUCP (Fred Smith) Organization: Agfa Compugraphic Division Lines: 39 OK. Thanks to all of you who sent me good answers to my question about reasons for zero-length arrays. Now I think I understand. In fact, I recall having seen code previously which used a zero-length array at the tail end of a structure. I thought at the time that it was a HORRIBLE way to write code. I STILL think so. Sure, it works (on some implementation!!!!). Sure, its also convenient and useful. Does that make it good C? Does that make it easy to figure out when you trip over it for the first time in somebody's undocumented piece of code? NO. I think that its convenience is not sufficient reason to insist that it should be a part of the language. After all, there are other conveniences which are used in certain implementations that are also not a part of the language as specified by X3J11, ususally for good reason. One reason that comes to mind is a conflict with the way arrays relate to pointers. For normal arrays, simply mentioning its name in a program evaluates to the address of the array. Now what is this address?? It is the address of the first element of the array! If the thing is declared as zero length, what do you get when you mention its address ?? I dunno, haven't tried it yet (I intend to), but I bet it makes no sense, whatever it is! Even if it does evaluate to some address somewhere, it certainly is not an address at which one would dare to store data (without, of course, the use of malloc to create some data space there)! I would guess that it is because of this kind of sticky issue that the committee chose not to embrace zero-length arrays. Sure, it would be nice if everybody's favorite feature (or abuse of the language) were specified in the standard. However, the guys onthe committee were also trying to make all the pieces fit together in a more-or-less logical manner, so as to reduce some of the hidden gotchas, and it seems to me that this particular one does have a few hidden gotchas. It certainly is easy enough to work around the "lack" of this "feature". Fred