Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!ukc!dcl-cs!gdt!gdr!exspes From: exspes@gdr.bath.ac.uk (P E Smee) Newsgroups: comp.lang.c Subject: Re: Zero Length Arrays Allowed in C Standard? Message-ID: <1989Dec12.110042.29290@gdt.bath.ac.uk> Date: 12 Dec 89 11:00:42 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: exspes@gdr.bath.ac.uk (P E Smee) Organization: University of Bristol c/o University of Bath Lines: 32 In article <8129@cg-atla.UUCP> fredex@cg-atla.UUCP (Fred Smith) writes: >Excuse me, but I must ask a stupid question. Why the !@#$ would anyone even want >to declare an array of zero size ???? One reason I haven't seen given yet is to provide a marker for the end of an entity. I could use such a beast (more or less) as follows (example slightly simplified)... struct fred { struct fred * last; struct fred * next; long offset; int thing; ... bunch of more data stuff char end_marker[0]; /* MUST BE LAST IN STRUCTURE */ }; .... bzero (&fred.offset, &fred.end_marker - &fred.offset); to provide an easy way of clearing a member of the list without disturbing its 2 list links (the first 2 pointers). At present I use an int end_marker as I don't trust size 0 arrays. This is quicker than zeroing each item in the struct separately, and I don't have to worry about possible padding -- where I would if I tried to work out the size of the bzero from the sizes of the data items in the region I want to zap. -- Paul Smee, Univ. of Bristol Comp. Centre, Bristol BS8 1TW (Tel +44 272 303132) Smee@bristol.ac.uk :-) (..!uunet!ukc!gdr.bath.ac.uk!exspes if you HAVE to)