Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Zero Length Arrays Allowed in C Standard? Message-ID: <11741@smoke.BRL.MIL> Date: 5 Dec 89 05:56:55 GMT References: <2298@jato.Jpl.Nasa.Gov> <11715@smoke.BRL.MIL> <480@codonics.COM> <1989Dec2.210042.12668@twwells.com> <8129@cg-atla.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 25 In article <8129@cg-atla.UUCP> fredex@cg-atla.UUCP (Fred Smith) writes: >Why the !@#$ would anyone even want to declare an array of zero size ???? There are several contexts in which it would be useful. The general philosophical answer is, since it could be useful and since we all agree that control structures that can loop zero times are preferable to ones that insist on looping at least once, why shouldn't the same considerations be applied to the data structures manipulated by such control structures? For example, suppose that one can individually configure a bunch of options when compiling an application, and that OPTA, etc. are either 1 or 0 to determine whether or not the option is to be supported at run time. Then one might find it convenient to have an array of run-time option enable/disable flags, or some similar data structure: bool opt_on[OPTA+OPTB+OPTC+...+OPTZ]; In the case where no option cupport was configured at compile time, it would be nice if the resulting 0-length array could merely be left as is, since we know that no accesses will be made to its contents at run time. Yet according to the C standard, that would be an illegal declaration, so we have to code in a special kludge just to take care of this special case.