home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 17080 < prev    next >
Encoding:
Text File  |  1992-11-24  |  1.4 KB  |  34 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!dkeisen
  3. From: dkeisen@leland.Stanford.EDU (Dave Eisen)
  4. Subject: Re: Is this ANSI?
  5. Message-ID: <1992Nov23.195804.24672@leland.Stanford.EDU>
  6. Sender: news@leland.Stanford.EDU (Mr News)
  7. Organization: Sequoia Peripherals, Inc.
  8. References: <24262@alice.att.com> <By6HMs.I4r@unx.sas.com> <1992Nov23.180808.19157@ncsu.edu>
  9. Date: Mon, 23 Nov 92 19:58:04 GMT
  10. Lines: 22
  11.  
  12. >
  13. >I asked my C mentor about this once, and he pointed out that the compiler is
  14. >free to store the members of the structure in any order.  Thus the compiler 
  15. >could store data[1] in memory before it stores data_len.  Then if you wrote
  16. >to data[1] you would clobber data_len.  
  17.  
  18. Your mentor was wrong. The ANSI standard requires structs to be
  19. laid out with the fields in the correct order. The only leeway that
  20. is allowed in setting up structs is that the compiler can put padding
  21. between fields in order to make sure the fields are aligned properly.
  22. There is no leeway to store fields in an order different from how the
  23. user defined the struct.
  24.  
  25. As far as I know all pre-ANSI compilers worked this way as well.
  26.  
  27.  
  28.  
  29. -- 
  30. Dave Eisen                               Sequoia Peripherals: (415) 967-5644
  31. dkeisen@leland.Stanford.EDU              Home:                (415) 321-5154
  32.        There's something in my library to offend everybody. 
  33.           --- Washington Coalition Against Censorship
  34.