home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!elroy.jpl.nasa.gov!usc!sol.ctr.columbia.edu!eff!world!ksr!jfw
- From: jfw@ksr.com (John F. Woods)
- Newsgroups: comp.std.c
- Subject: Re: Character arrays in structures and address alignment -- any standard?
- Message-ID: <14235@ksr.com>
- Date: 28 Jul 92 16:20:16 EDT
- References: <1992Jul26.225252.4487@anasazi.com> <1992Jul27.183622.794@taumet.com> <1992Jul28.063356.28005@sq.sq.com> <14216@ksr.com> <bs3x0j.ilr@wang.com>
- Sender: news@ksr.com
- Lines: 42
-
- smayo@wang.com (Scott Mayo) writes:
- >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.
- >In spirit, there is something askew in this question.
-
- The topic here is what the Standard does and doesn't allow. The usual way
- of inferring a restriction or requirement when it is too subtle to read
- directly from the Standard is to demonstrate a program which is strictly
- conforming but which does not behave in the expected way if the proposed
- restriction or requirement is met. For example, it was claimed at one time
- that, although the Standard lists two and only two kinds of null pointer
- constants (an integral constant zero or an integral constant zero cast to
- void *), a compiler could make NULL expand into (char *)0, because a strictly
- conforming program couldn't tell the difference. Doug Gwyn (I think) then
- demonstrated one that could, taking advantage of the # operator.
-
- What the standard says about alignment of things in a structure is:
-
- "Each non-bit-field member of a structure or union object is aligned
- in an implementation-defined manner appropriate to its type."
-
- An implementation must document its strategy, but
-
- "For all types, structure members are aligned on 16-byte boundaries,
- except on Fat Tuesday and Christmas, when for all types, structure
- members are aligned on 64-byte boundaries for good luck."
-
- is perfectly acceptable, even if everything is addressable on arbitrary byte
- boundaries. If you would quibble with whether that is "appropriate", either
- write a SCP that exposes the error, or chalk it up to "quality of
- implementation".
-
- After all, the Standard explicitly does not describe "the mechanism by which
- C programs are invoked for use by a data-processing system", but this does not
- therefore imply that a conforming system may *not* invoke C programs...
-