struct and class size guarantees

  • Thread starter =?ISO-8859-1?Q?Tanguy_Fautr=E9?=
  • Start date
?

=?ISO-8859-1?Q?Tanguy_Fautr=E9?=

Hi,

I was wondering whether you can always assume that

sizeof(foo) == sizeof(T) * Size;

for

template <class T, size_t Size>
class foo
{
T bar[Size];
};

considering that the foo class will never have any virtual functions.
Or is the compiler allowed to add padding or extra information, even in
that case?

Regards,

Tanguy
 
V

Victor Bazarov

Tanguy said:
I was wondering whether you can always assume that

sizeof(foo) == sizeof(T) * Size;

for

template <class T, size_t Size>
class foo
{
T bar[Size];
};

considering that the foo class will never have any virtual functions.

No, you cannot assume that.
Or is the compiler allowed to add padding or extra information, even in
that case?

Yes, most certainly.

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top