Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mcnc!gatech!rutgers!mtune!codas!cpsc6a!rtech!wrs!dg From: dg@wrs.UUCP (David Goodenough) Newsgroups: comp.lang.c Subject: Re: Turbo C and "empty" arrays Message-ID: <240@wrs.UUCP> Date: Tue, 14-Jul-87 14:01:01 EDT Article-I.D.: wrs.240 Posted: Tue Jul 14 14:01:01 1987 Date-Received: Fri, 17-Jul-87 07:32:56 EDT References: <218@picuxa.UUCP> <23127@sun.uucp> <6105@brl-smoke.ARPA> Reply-To: dg@wrs.UUCP (David Goodenough) Organization: Wind River Systems, Emeryville, CA Lines: 46 In article <6105@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB)) writes: >In article <23127@sun.uucp> guy%gorodish@Sun.COM (Guy Harris) writes: >>... they clearly indicate that an initializer of "{}" is NOT valid, >>and that there must be at least one initializer. > >This is perhaps a good opportunity to remind people that I'm the POC for >a special interest group concerning 0-sized data objects in C (which >aren't currently legal). If you have good examples that illustrate >just why you need 0-sized objects, send them to me and I'll use them as >ammunition in support of legalizing them. One place where a zero sized array would have been useful was in a tree structure module I once wrote: struct node { struct node *parent; struct node *left; struct node *right; int object[0]; /* << zero sized declaration */ } Now when I want to allocate memory for a node that can hold anything I could write: newnode = node_alloc(sizeof(object)); where node_alloc() is declared: node_alloc(size) unsigned size; { return(malloc(sizeof(struct node) + size); } My reason for the zero sized object in struct node is that the sizeof(struct node) simply gets space for the three pointers, and size is responsible for the object - my intention was to keep the two bits quite distinct, yet still allow for variable sized objects. -- dg@wrs.UUCP - David Goodenough +---+ | +-+-+ +-+-+ | +---+