Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > struct and class size guarantees

Reply
Thread Tools

struct and class size guarantees

 
 
=?ISO-8859-1?Q?Tanguy_Fautr=E9?=
Guest
Posts: n/a
 
      06-02-2004
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
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-02-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can we rely on any guarantees based on memory layout and default destructor Fredrik Eriksson C++ 7 10-19-2011 01:58 PM
Array definition guarantees mdh C Programming 14 08-14-2008 11:35 PM
Alignment guarantees? bytebro C++ 6 03-18-2008 10:23 AM
Exception guarantees for STL container constructors Shane Groff C++ 1 10-02-2004 02:39 PM
std::multimap insertion order guarantees Tanguy Fautré C++ 13 10-06-2003 04:34 PM



Advertisments