🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #20645

Re: Sorting struct members for alignment (was Re: Unaligned Acc

#20645
From: -for inetd server command
Date: Tue, 04 Apr 1989 20:28
35 lines
2444 bytes
In article <16360@cup.portal.com> Devin_E_Ben-Hur@cup.portal.com writes:
>Sorry, folks, this is from K&R I, p196, "8.5 Structure and union declarations
>... Within a structure, the objects declared have addresses which increase
>as their declarations are read left-to-right."

>There is similar language in the pANS and K&R II.  Reordering C structure
>members has never been and is not now correct behavior for a C compiler.

Let's ignore sorting ALL structure elements for a moment.  Let's consider a
compiler which simply puts each new structure element at the first offset
where that new element fits.  Many times such a compiler may have to put the
new element at the end (as per K&R and pANS).  Sometimes the compiler could
"take back" padding, that the compiler previously assumed was needed
(expressly forbidden by K&R and pANS).

Let's assume the compiler treats "sub-structures" as opaque black boxes and
doesn't try to stuff anything inside a sub-structure.  This will still allow
the compiler to implement structure assignment (e.g. to the sub-structures) as
simple memory copies.

This way programs that require certain structure elements at particular
offsets on a particular machine, could specify structure elements (e.g. pad1
pad2 ...) where padding would otherwise take place.

Under such a scheme, what otherwise portable programs would quit working?

Obviously, expressions like:

    &ptr->fieldx - &ptr->fieldy

may be (unexpectedly) negative.  I'm not sure that even with the needed casts,
that this sort of thing is portable.

Paul Scherf, Tektronix, Box 1000, MS 61-028, Wilsonville, OR, USA
paulsc@orca.WV.Tek.com     503-685-2734     tektronix!orca!paulsc
Technical Details
Message-ID: <11234@tekecs.GWD.TEK.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!tektronix!orca!tekecs!nobody
References: <37196@bbn.COM> <1989Mar16.190043.23227@utzoo.uucp> <24889@amdcad.AMD.COM> <355@bnr-fos.UUCP> <13@microsoft.UUCP> <362@bnr-fos.UUCP> <59@microsoft.UUCP> <11118@pur-ee.UUCP> <16360@cup.portal.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!tektronix!orca!tekecs!nobody
From: nobody@tekecs.GWD.TEK.COM (-for inetd server command)
Newsgroups: comp.arch
Subject: Re: Sorting struct members for alignment (was Re: Unaligned Acc
Summary: What if ...?
Keywords: C, structure member alignment
Message-ID: <11234@tekecs.GWD.TEK.COM>
Date: 4 Apr 89 20:28:44 GMT
References: <37196@bbn.COM> <1989Mar16.190043.23227@utzoo.uucp> <24889@amdcad.AMD.COM> <355@bnr-fos.UUCP> <13@microsoft.UUCP> <362@bnr-fos.UUCP> <59@microsoft.UUCP> <11118@pur-ee.UUCP> <16360@cup.portal.com>
Reply-To: paulsc@radio_flyer.UUCP (Paul Scherf)
Organization: Tektronix, Inc., Wilsonville, OR
Lines: 35