This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: attribute "unpadded"


> I wonder if we should not just give the type two sizes, an unpadded one 
> and a padded one.  Then the unpadded one would be used for operations such 
> as sizeof, and in creating larger records, but the padded one could be 
> used for arrays and pointer arithmetic operations.  That is, an array 
> would consist of a series of such structures laid out at their natural 
> alignment.

That would violate C semantics: sizeof() must return the padded length.
If it did not, the common C idiom

	struct foo *p = malloc(array_length * sizeof(struct foo));

would break.

> It does mean that using code such as n * sizeof(struct A) would be 
> undefined, but it would mean that some array operations would be well 
> defined.

But C already specifies the meaning of n * sizeof(struct A) and assures
that if you pass such an argument to malloc, the result will hold n A's,
complete with padding.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]