🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #130

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

#130
From: Mark Brader
Date: Tue, 28 Jul 1992 06:33
24 lines
1348 bytes
> |  struct {
> |    char a[3];
> |    char b[2];
> |  } x;
> 
> 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.

> You cannot rely on the offset of member 'b' being the
> same on different implementations.

This conclusion is correct, though; there's nothing to say that array-of-
character types have to have the alignment requirement as character types.
For example, the compiler is at liberty to force all arrays of char to
begin on a 4-byte boundary, and therefore insert 1 byte between a and b.
-- 
Mark Brader	  "I'm not a lawyer, but I'm pedantic and that's just as good."
utzoo!sq!msb, msb@sq.com				       -- D Gary Grady

This article is in the public domain.
Technical Details
Message-ID: <1992Jul28.063356.28005@sq.sq.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!wildcan!sq!msb
References: <1992Jul26.225252.4487@anasazi.com> <1992Jul27.183622.794@taumet.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!wildcan!sq!msb
From: msb@sq.sq.com (Mark Brader)
Subject: Re: Character arrays in structures and address alignment -- any standard?
Message-ID: <1992Jul28.063356.28005@sq.sq.com>
Organization: SoftQuad Inc., Toronto, Canada
References: <1992Jul26.225252.4487@anasazi.com> <1992Jul27.183622.794@taumet.com>
Date: Tue, 28 Jul 92 06:33:56 GMT
Lines: 24