home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / std / c / 2369 < prev    next >
Encoding:
Text File  |  1992-07-27  |  1.3 KB  |  35 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: Character arrays in structures and address alignment -- any standard?
  5. Message-ID: <1992Jul28.063356.28005@sq.sq.com>
  6. Organization: SoftQuad Inc., Toronto, Canada
  7. References: <1992Jul26.225252.4487@anasazi.com> <1992Jul27.183622.794@taumet.com>
  8. Date: Tue, 28 Jul 92 06:33:56 GMT
  9. Lines: 24
  10.  
  11. > |  struct {
  12. > |    char a[3];
  13. > |    char b[2];
  14. > |  } x;
  15. > The Standard allows arbitrary padding between fields and after the
  16. > last field.
  17.  
  18. Not quite; it allows padding so that the members are correctly aligned
  19. for their types.  It does not say anything about padding being permitted
  20. for any other reasons, and my interpretation is that it isn't.
  21.  
  22. > You cannot rely on the offset of member 'b' being the
  23. > same on different implementations.
  24.  
  25. This conclusion is correct, though; there's nothing to say that array-of-
  26. character types have to have the alignment requirement as character types.
  27. For example, the compiler is at liberty to force all arrays of char to
  28. begin on a 4-byte boundary, and therefore insert 1 byte between a and b.
  29. -- 
  30. Mark Brader      "I'm not a lawyer, but I'm pedantic and that's just as good."
  31. utzoo!sq!msb, msb@sq.com                       -- D Gary Grady
  32.  
  33. This article is in the public domain.
  34.