home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / std / c / 2372 < prev    next >
Encoding:
Text File  |  1992-07-28  |  2.0 KB  |  41 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!das.wang.com!wang!smayo
  3. From: smayo@wang.com (Scott Mayo)
  4. Subject: Re: Character arrays in structures and address alignment -- any standard?
  5. Organization: Wang Labs, Lowell MA, USA
  6. Date: Tue, 28 Jul 92 16:12:18 GMT
  7. Message-ID: <bs3x0j.ilr@wang.com>
  8. References: <1992Jul26.225252.4487@anasazi.com> <1992Jul27.183622.794@taumet.com> <1992Jul28.063356.28005@sq.sq.com> <14216@ksr.com>
  9. Sender: news@wang.com
  10. Lines: 29
  11.  
  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.  
  20. >Please show a strictly conforming program which can tell the difference
  21. >between "necessary" padding and "unnecessary" padding.
  22.  
  23. In spirit, there is something askew in this question. The usual intent
  24. behind writing a strictly conforming program is to make it as portable
  25. as possible. In that case, the last thing a program should be written to
  26. know about is if padding occurs, how it occurs, and when. It varies from
  27. environment to environment, and for all you know, it varies wildly at
  28. different times of day on a given machine. The compiler is supposed to worry
  29. about it - not you. The compiler can pad anything for any reason it
  30. likes, as long as pointer subtraction and comparisons work.
  31.  
  32. In practice, you can detect padding by generating pointers to two objects
  33. (in the same array or struct of course), casting them to char*, and
  34. subtracting. If you get an unexpected value, padding has occured. Whether
  35. it was "necessary" or not is hardly relevant, a quality of implementation
  36. issue at best, I'd think.
  37. --
  38. ..For to contend in words is not to care how error is overcome by truth,
  39.    but how your speech is preferred to that of another.      -Augustine
  40. smayo@wang.com
  41.