Article View: comp.std.c
Article #3310Re: Structure walking
From: Mark Brader
Date: Thu, 28 Jan 1993 02:59
Date: Thu, 28 Jan 1993 02:59
69 lines
3456 bytes
3456 bytes
> > (d) The offset of the (n+1)th member of a structure is the offset of > > the nth member of the structure, plus the size of the nth member, > > rounded up to the alignment requirement of the type of the (n+1)th > > member. > False. ANSI 3.5.2.1 (emphasis mine): > Each non-bit-field member of a structure or union object is aligned > in an implementation-defined manner *appropriate* to its type. > > Note that it says "appropriate to", not "required by". An > implementation has a great deal of latitude in how it aligns members. I disagree with "False". I think this one is "Unknown, until there is an interpretation ruling". 3.5.2.1 also says: There may ... be unnamed padding within a structure object ... as *necessary* to achieve the appropriate alignment. It isn't clear to be whether this means the alleged implementation-defined alignment referred to in the last quoted message, or simply the alignment requirement appropriate to the type of the member. If it is the latter case, then the other passage is merely a complicated way of saying "in the manner appropriate to its type, which (as you know) is implementation- defined". And the answer to (d) hinges on this point. Of course, if it's critical, prudence requires you to assume False. > > (e) The alignment required by the structure is equal to the most > > restrictive alignment of any of its members. > > True, but see (a). I say False! It's at least as restrictive, but it could be more restrictive. If you believe otherwise, please cite chapter and verse. > > (f) The size of the structure is the offset of the last member of the > > structure, plus the size of the last member, rounded up to alignment > > required by the structure. > > False. ANSI 3.5.2.1 again: > There may also be unnamed padding at the end of a structure or > union, as necessary to achieve the *appropriate* alignment were > the structure or union to be an element of an array. > Again, it says "appropriate", not "required". But that padding yields the "alignment required by the structure"! So this is True, unless I'm misunderstanding the question. > It is generally reguarded as true that the Standard contains sufficient > requirements scattered about its various sections to require that all > structure pointers have the same representation. I have no reason to disbelieve this, but I've never seen the proof outlined, and it would be interesting to see it. It would also be interesting to see if someone disbelieves the proof when it *is* presented -- just as there are people who disbelieve the standard proof that the struct hack is strictly conforming, which also draws on "requirements scattered about ... various sections" of the standard. -- Mark Brader "Sir, your composure baffles me. A single counter- SoftQuad Inc. example refutes a conjecture as effectively as ten. Toronto ... Hands up! You have to surrender." utzoo!sq!msb, msb@sq.com -- Imre Lakatos This article is in the public domain.
Technical Details
Message-ID:
<1993Jan28.025939.26847@sq.sq.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!wildcan!sq!msbReferences:
<1993Jan25.213543.25499@pony.Ingres.COM> <565@heimdall.sdrc.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!wildcan!sq!msb From: msb@sq.sq.com (Mark Brader) Subject: Re: Structure walking Message-ID: <1993Jan28.025939.26847@sq.sq.com> Organization: SoftQuad Inc., Toronto, Canada References: <1993Jan25.213543.25499@pony.Ingres.COM> <565@heimdall.sdrc.com> Date: Thu, 28 Jan 93 02:59:39 GMT Lines: 69