Block Initialization; structs and sizeof

Mark Brader msb at dciem.UUCP
Thu Oct 16 05:14:36 AEST 1986


I wrote:
>	struct str {int i; char c;} arr[2], sca;
>	char buf;
> The most recent ANSI draft that I've examined specifies that if sizeof is
> applied to a structure type, the result is the size of such a structure
> including any trailing padding that would be necessary in an array of
> such structures. ...

> However, the scalar struct sca is not required to have [the] padding.
> ... Thus some compilers may decide to economize
> on storage and place another variable, say buf, [where it would be] ...

According to mail from Larry Rosler, this has been fixed, and the current
draft reads:

# There may also be unnamed padding at the end of a structure,
# as necessary to achieve the appropriate alignment WERE the
# structure to be a member of an array.  [Emphasis added]

He has suggested that the definition of sizeof be simplified to remove
the "that would be necessary..." part, which is now redundant.

Mark Brader, utzoo!dciem!msb
	"You take the bottle out of the box, take the cotton out of the
	 bottle ... and if they'd just used the box and not used the bottle
	 ... look at this, all these pills would've fitted into the box and
	 they'd have had room for 3 times as much cotton!"   -- Andy Rooney

More information about the Comp.lang.c mailing list