🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #135

Re: Character arrays in structures and address alignment -- any standard?

#135
From: Scott Mayo
Date: Tue, 28 Jul 1992 16:12
29 lines
2044 bytes
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 usual intent
behind writing a strictly conforming program is to make it as portable
as possible. In that case, the last thing a program should be written to
know about is if padding occurs, how it occurs, and when. It varies from
environment to environment, and for all you know, it varies wildly at
different times of day on a given machine. The compiler is supposed to worry
about it - not you. The compiler can pad anything for any reason it
likes, as long as pointer subtraction and comparisons work.

In practice, you can detect padding by generating pointers to two objects
(in the same array or struct of course), casting them to char*, and
subtracting. If you get an unexpected value, padding has occured. Whether
it was "necessary" or not is hardly relevant, a quality of implementation
issue at best, I'd think.
--
..For to contend in words is not to care how error is overcome by truth,
   but how your speech is preferred to that of another.      -Augustine
smayo@wang.com
Technical Details
Message-ID: <bs3x0j.ilr@wang.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!das.wang.com!wang!smayo
References: <1992Jul26.225252.4487@anasazi.com> <1992Jul27.183622.794@taumet.com> <1992Jul28.063356.28005@sq.sq.com> <14216@ksr.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!sparky!uunet!das.wang.com!wang!smayo
From: smayo@wang.com (Scott Mayo)
Subject: Re: Character arrays in structures and address alignment -- any standard?
Organization: Wang Labs, Lowell MA, USA
Date: Tue, 28 Jul 92 16:12:18 GMT
Message-ID: <bs3x0j.ilr@wang.com>
References: <1992Jul26.225252.4487@anasazi.com> <1992Jul27.183622.794@taumet.com> <1992Jul28.063356.28005@sq.sq.com> <14216@ksr.com>
Sender: news@wang.com
Lines: 29