Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 03 Mar 2002 18:11:29 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        "Brian T.Schellenberger" <bts@babbleon.org>
Cc:        Erik Trulsson <ertr1013@student.uu.se>, Ian <freebsd@damnhippie.dyndns.org>, freebsd-hackers <freebsd-hackers@FreeBSD.ORG>
Subject:   Re: A few questions about a few includes
Message-ID:  <3C82D7D1.F9AD882C@mindspring.com>
References:  <XFMail.20020303091938.conrads@cox.net> <B8A7AB05.AAE6%freebsd@damnhippie.dyndns.org> <20020303180029.GA56041@student.uu.se> <20020304012020.A1681BA05@i8k.babbleon.org>

next in thread | previous in thread | raw e-mail | index | archive | help
"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 majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3C82D7D1.F9AD882C>