Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!usenet.ins.cwru.edu!hal!ncoast!allbery From: allbery@NCoast.ORG (Brandon S. Allbery) Newsgroups: comp.unix.i386 Subject: Re: Message queues. Possibly dumb mistake. Message-ID: <1989Dec8.234510.8542@NCoast.ORG> Date: 8 Dec 89 23:45:10 GMT References: <1989Dec7.150205.12104@antel.uucp> Reply-To: allbery@ncoast.ORG (Brandon S. Allbery) Followup-To: comp.unix.i386 Organization: North Coast Public Access UN*X, Cleveland, OH Lines: 38 As quoted from <1989Dec7.150205.12104@antel.uucp> by geoff@antel.uucp (Geoff Vona): +--------------- | struct msgbuf { | long mtype; | char mtext[1]; | }; +--------------- "char xxx[1];" is a convention for an "extensible" structure; you can't declare an array of size 0, so you declare it of size 1 and allocate it as struct msgbuf *p = malloc(sizeof *p + msglen - 1); This, BTW, is a rather miserable -- and potentially non-portable -- way of doing things; a better design would have been to pass mtype as an argument on msgsnd() and return it from msgrcv(), and pass the message itself as a (char *) (or (void *) for ANSI C folks). But they didn't ask my opinion before designing it. +--------------- | struct msgbuf { | long mtype; | char mtext[]; | }; +--------------- This is illegal C; it does, however, express that the array mtext extends immediately after the structure. This topic comes up every so often, so I've decided to post. ++Brandon -- Brandon S. Allbery allbery@NCoast.ORG, BALLBERY (MCI Mail), ALLBERY (Delphi) uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery@hal.cwru.edu bsa@telotech.uucp *(comp.sources.misc mail to comp-sources-misc[-request]@backbone.site, please)* *Third party vote-collection service: send mail to allbery@uunet.uu.net (ONLY)* expnet.all: Experiments in *net management and organization. Mail me for info.