By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

struct and class size guarantees

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Tanguy Fautré wrote:
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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.