Subject: Use of sizeof()
To: None <current-users@NetBSD.ORG>
From: Robert Black <r.black@ic.ac.uk>
List: current-users
Date: 07/11/1995 10:47:11
I have a question for anyone with intimate knowledge of the K&R C standard.
There is some code in NetBSD (generic SCSI is one place) which makes
assumptions about the alignment of structs. This takes the form of assuming
that structs are only aligned to the alignment of their largest data type. For
example with a structure like
typedef struct
{
short a;
short b;
short c;
} foo;
it is assumed that sizeof(foo) == 6. Some compilers (notably gcc/arm) will give
a value of 8 because all structs are word aligned regardless of contents so
sizeof() returns the amount of space required to store a struct in an array.
Which is broken: the NetBSD code or the compiler?
Rob Black