home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / std / c / 2374 < prev    next >
Encoding:
Internet Message Format  |  1992-07-28  |  2.7 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!usc!sol.ctr.columbia.edu!eff!world!ksr!jfw
  2. From: jfw@ksr.com (John F. Woods)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Character arrays in structures and address alignment -- any standard?
  5. Message-ID: <14235@ksr.com>
  6. Date: 28 Jul 92 16:20:16 EDT
  7. References: <1992Jul26.225252.4487@anasazi.com> <1992Jul27.183622.794@taumet.com> <1992Jul28.063356.28005@sq.sq.com> <14216@ksr.com> <bs3x0j.ilr@wang.com>
  8. Sender: news@ksr.com
  9. Lines: 42
  10.  
  11. smayo@wang.com (Scott Mayo) writes:
  12. >jfw@ksr.com (John F. Woods) writes:
  13. >>msb@sq.sq.com (Mark Brader) writes:
  14. >>>> The Standard allows arbitrary padding between fields and after the
  15. >>>> last field.
  16. >>>Not quite; it allows padding so that the members are correctly aligned
  17. >>>for their types.  It does not say anything about padding being permitted
  18. >>>for any other reasons, and my interpretation is that it isn't.
  19. >>Please show a strictly conforming program which can tell the difference
  20. >>between "necessary" padding and "unnecessary" padding.
  21. >In spirit, there is something askew in this question.
  22.  
  23. The topic here is what the Standard does and doesn't allow.  The usual way
  24. of inferring a restriction or requirement when it is too subtle to read
  25. directly from the Standard is to demonstrate a program which is strictly
  26. conforming but which does not behave in the expected way if the proposed
  27. restriction or requirement is met.  For example, it was claimed at one time
  28. that, although the Standard lists two and only two kinds of null pointer
  29. constants (an integral constant zero or an integral constant zero cast to
  30. void *), a compiler could make NULL expand into (char *)0, because a strictly
  31. conforming program couldn't tell the difference.  Doug Gwyn (I think) then
  32. demonstrated one that could, taking advantage of the # operator.
  33.  
  34. What the standard says about alignment of things in a structure is:
  35.  
  36.     "Each non-bit-field member of a structure or union object is aligned
  37.     in an implementation-defined manner appropriate to its type."
  38.  
  39. An implementation must document its strategy, but
  40.  
  41.     "For all types, structure members are aligned on 16-byte boundaries,
  42.     except on Fat Tuesday and Christmas, when for all types, structure
  43.     members are aligned on 64-byte boundaries for good luck."
  44.  
  45. is perfectly acceptable, even if everything is addressable on arbitrary byte
  46. boundaries.  If you would quibble with whether that is "appropriate", either
  47. write a SCP that exposes the error, or chalk it up to "quality of
  48. implementation".
  49.  
  50. After all, the Standard explicitly does not describe "the mechanism by which
  51. C programs are invoked for use by a data-processing system", but this does not
  52. therefore imply that a conforming system may *not* invoke C programs...
  53.