Variable-length messages.

Henry Spencer henry at utzoo.uucp
Sun Oct 23 09:13:17 AEST 1988


In article <919 at goofy.megatest.UUCP> djones at megatest.UUCP (Dave Jones) writes:
>> 	struct message {
>> 		int msgType;		/* msg type code */
>> 		int msgLength;		/* length of msg body */
>> 		char msgBody[1];	/* variable length msg body */
>> 	};
>
>This looks unsafe to me.  That one-char-long "msgBody" can be
>packed into the structure at any of a number of different places,
>depending on the compiler's alignment strategy.

No:  X3J11 specifically states that struct member addresses are in ascending
order, and enough existing code assumes this that there should be relatively
few compilers that violate it.  (Of course, this is little comfort if you
are constrained to use such a compiler...)
-- 
The meek can have the Earth;    |    Henry Spencer at U of Toronto Zoology
the rest of us have other plans.|uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list