Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can wrapping a type in a struct cause additional padding? [duplicate]

Possible Duplicate:
Size of struct with a single element

Given any type A and the following struct:

struct S
{
    A a;
};

Are there any cases where sizeof(S) is greater than sizeof(A)?

For example, can sizeof(std::array<T, n>) be greater than sizeof(T[n])?

like image 355
fredoverflow Avatar asked Sep 01 '11 11:09

fredoverflow


1 Answers

Being able to use A inside of S means that the compiler already has knowledge of the structure of A and has already added padding bytes to it. I see no reason for it to add further padding to S, as it already is aligned.

like image 144
Luchian Grigore Avatar answered Oct 07 '22 07:10

Luchian Grigore