"Brian T.Schellenberger" wrote:
> I can't even imagine how one *would* write a compiler where this would
> fail--does anybody know the putative risk that led ANSI to "ban" this (IMHO)
> perfectly-reasonable bahvior?

Order of structure elements is undefined.  Zero length arrays
are undefined.  Also, packing is undefined.

You can basically get arouns all of this by declaring the
array to be 1 byte, e.g.:

struct  pargs {
 u_int   ar_ref;         /* Reference count */
 u_int   ar_length;      /* Length */
 u_char  ar_args[1];     /* Arguments */
};

And then sizing the allocation unit relatively, e.g., dont
use:

        sizeof(struct pargs) + byte_count

use instead:

        (int)&((struct pargs *)0)->ar_args + byte_count;

To get the size of the elements up to but not including
the one byte declared, regardless of alignment or packing.

-- Terry

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to