Message queues. Possibly dumb mistake.

Brandon S. Allbery allbery at NCoast.ORG
Sat Dec 9 10:45:10 AEST 1989


As quoted from <1989Dec7.150205.12104 at antel.uucp> by geoff at 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 at NCoast.ORG, BALLBERY (MCI Mail), ALLBERY (Delphi)
uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery at hal.cwru.edu bsa at telotech.uucp
*(comp.sources.misc mail to comp-sources-misc[-request]@backbone.site, please)*
*Third party vote-collection service: send mail to allbery at uunet.uu.net (ONLY)*
expnet.all: Experiments in *net management and organization.  Mail me for info.



More information about the Comp.unix.i386 mailing list