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