From owner-freebsd-hackers Sun Mar 3 18:11:57 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from gull.prod.itd.earthlink.net (gull.mail.pas.earthlink.net [207.217.120.84]) by hub.freebsd.org (Postfix) with ESMTP id A0DA337B400 for ; Sun, 3 Mar 2002 18:11:53 -0800 (PST) Received: from pool0165.cvx40-bradley.dialup.earthlink.net ([216.244.42.165] helo=mindspring.com) by gull.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16hhx2-0002UO-00; Sun, 03 Mar 2002 18:11:44 -0800 Message-ID: <3C82D7D1.F9AD882C@mindspring.com> Date: Sun, 03 Mar 2002 18:11:29 -0800 From: Terry Lambert X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: "Brian T.Schellenberger" Cc: Erik Trulsson , Ian , freebsd-hackers Subject: Re: A few questions about a few includes References: <20020303180029.GA56041@student.uu.se> <20020304012020.A1681BA05@i8k.babbleon.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG "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