home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / std / c / 3428 < prev    next >
Encoding:
Text File  |  1993-01-27  |  3.3 KB  |  80 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!uunet.ca!wildcan!sq!msb
  3. From: msb@sq.sq.com (Mark Brader)
  4. Subject: Re: Structure walking
  5. Message-ID: <1993Jan28.025939.26847@sq.sq.com>
  6. Organization: SoftQuad Inc., Toronto, Canada
  7. References: <1993Jan25.213543.25499@pony.Ingres.COM> <565@heimdall.sdrc.com>
  8. Date: Thu, 28 Jan 93 02:59:39 GMT
  9. Lines: 69
  10.  
  11. > > (d) The offset of the (n+1)th member of a structure is the offset of
  12. > >     the nth member of the structure, plus the size of the nth member,
  13. > >     rounded up to the alignment requirement of the type of the (n+1)th
  14. > >     member.
  15.  
  16. > False.  ANSI 3.5.2.1 (emphasis mine):
  17. >     Each non-bit-field member of a structure or union object is aligned
  18. >     in an implementation-defined manner *appropriate* to its type.
  19. >
  20. > Note that it says "appropriate to", not "required by".  An
  21. > implementation has a great deal of latitude in how it aligns members.
  22.  
  23. I disagree with "False".  I think this one is "Unknown, until there is an
  24. interpretation ruling".  3.5.2.1 also says:
  25.  
  26.     There may ... be unnamed padding within a structure object ...
  27.     as *necessary* to achieve the appropriate alignment.
  28.  
  29. It isn't clear to be whether this means the alleged implementation-defined
  30. alignment referred to in the last quoted message, or simply the alignment
  31. requirement appropriate to the type of the member.  If it is the latter
  32. case, then the other passage is merely a complicated way of saying "in
  33. the manner appropriate to its type, which (as you know) is implementation-
  34. defined".  And the answer to (d) hinges on this point.
  35.  
  36. Of course, if it's critical, prudence requires you to assume False.
  37.  
  38.  
  39. > > (e) The alignment required by the structure is equal to the most
  40. > >     restrictive alignment of any of its members.
  41. > True, but see (a).
  42.  
  43. I say False!  It's at least as restrictive, but it could be more restrictive.
  44. If you believe otherwise, please cite chapter and verse.
  45.  
  46.  
  47. > > (f) The size of the structure is the offset of the last member of the
  48. > >     structure, plus the size of the last member, rounded up to alignment
  49. > >     required by the structure.
  50. > False.  ANSI 3.5.2.1 again:
  51. >     There may also be unnamed padding at the end of a structure or
  52. >     union, as necessary to achieve the *appropriate* alignment were
  53. >     the structure or union to be an element of an array.
  54. > Again, it says "appropriate", not "required".
  55.  
  56. But that padding yields the "alignment required by the structure"!  So this
  57. is True, unless I'm misunderstanding the question.
  58.  
  59.  
  60. > It is generally reguarded as true that the Standard contains sufficient
  61. > requirements scattered about its various sections to require that all
  62. > structure pointers have the same representation.
  63.  
  64. I have no reason to disbelieve this, but I've never seen the proof outlined,
  65. and it would be interesting to see it.  It would also be interesting to see
  66. if someone disbelieves the proof when it *is* presented -- just as there are
  67. people who disbelieve the standard proof that the struct hack is strictly
  68. conforming, which also draws on "requirements scattered about ... various
  69. sections" of the standard.
  70.  
  71. -- 
  72. Mark Brader         "Sir, your composure baffles me.  A single counter-
  73. SoftQuad Inc.          example refutes a conjecture as effectively as ten.
  74. Toronto              ... Hands up!  You have to surrender."
  75. utzoo!sq!msb, msb@sq.com                 -- Imre Lakatos
  76.  
  77. This article is in the public domain.
  78.