home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c
- Path: sparky!uunet!twwells!bill
- From: bill@twwells.com (T. William Wells)
- Subject: Re: Character arrays in structures and address alignment -- any standard?
- Organization: None, Mt. Laurel, NJ
- References: <1992Jul27.183622.794@taumet.com> <1992Jul28.063356.28005@sq.sq.com> <14216@ksr.com>
- Message-ID: <Bs5pMJ.3nM@twwells.com>
- Date: Wed, 29 Jul 1992 15:27:53 GMT
- Lines: 35
-
- In article <14216@ksr.com> jfw@ksr.com (John F. Woods) writes:
- : msb@sq.sq.com (Mark Brader) writes:
- : >> The Standard allows arbitrary padding between fields and after the
- : >> last field.
- : >Not quite; it allows padding so that the members are correctly aligned
- : >for their types. It does not say anything about padding being permitted
- : >for any other reasons, and my interpretation is that it isn't.
- :
- : Please show a strictly conforming program which can tell the difference
- : between "necessary" padding and "unnecessary" padding.
-
- For example:
-
- typedef struct {
- int x;
- int y;
- } foo;
- foo z;
-
- main()
- {
- printf("%d\n", (offsetof(foo, y) - offset(foo, x)) - sizeof(int));
- return (0);
- }
-
- should print 0 on any standards conforming compiler, if it is true
- that the standard permits only padding for the purpose of
- creating proper alignment. (I'll not argue the question of
- whether it does. Since it would be a daft compiler that added
- padding for any reason other than alignment, I think it not worth
- arguing.)
-
- ---
- Bill { uunet | decwrl | telesci }!twwells!bill
- bill@twwells.com
-