T
thomas
struct A{
int a;
char b;
};
class B{
int a;
char b;
};
sizeof(A)=6; sizeof(B)=8. why?
int a;
char b;
};
class B{
int a;
char b;
};
sizeof(A)=6; sizeof(B)=8. why?
thomas said:struct A{
int a;
char b;
};
class B{
int a;
char b;
};
sizeof(A)=6; sizeof(B)=8. why?
thomas said:struct A{
int a;
char b;
};
class B{
int a;
char b;
};sizeof(A)=6; sizeof(B)=8. why?
Hm... This is probably covered in your compiler documentation. Try
reading it. The Standard does not dictate what the sizeshould be.
It's "implementation-defined".
There is a difference between your types, you know that, yes?
V
Hm... This is probably covered in your compiler documentation. Try
reading it. The Standard does not dictate what the sizeshould be..
It's "implementation-defined".
There is a difference between your types, you know that, yes?
I don't know. I'm using vs2005.
I suppose "struct" and "class" should be equivalent except the default
privilege.
There's no reason to set different padding, if my understanding is
right.- Hide quoted text -
- Show quoted text -
Fred said:thomas wrote:
struct A{
int a;
char b;
};
class B{
int a;
char b;
};
sizeof(A)=6; sizeof(B)=8. why?
Hm... This is probably covered in your compiler documentation. Try
reading it. The Standard does not dictate what the sizeshould be.
It's "implementation-defined".
There is a difference between your types, you know that, yes?
V
I don't know. I'm using vs2005.
I suppose "struct" and "class" should be equivalent except the default
privilege.
There's no reason to set different padding, if my understanding is
right.- Hide quoted text -
- Show quoted text -
Who has a 'this', and who doesn't?
Fred said:thomas wrote:
struct A{
int a;
char b;
};
class B{
int a;
char b;
};
sizeof(A)=6; sizeof(B)=8. why?
Hm... This is probably covered in your compiler documentation. Try
reading it. The Standard does not dictate what the sizeshould be.
It's "implementation-defined".
There is a difference between your types, you know that, yes?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I don't know. I'm using vs2005.
I suppose "struct" and "class" should be equivalent except the default
privilege.
There's no reason to set different padding, if my understanding is
right.- Hide quoted text -
- Show quoted text -
Who has a 'this', and who doesn't?
Nobody "has a 'this'" since there are no non-static member functions.
'this' only exists in that context.
OTOH, IIUIC, the 'struct' is an aggregate and the 'class' isn't in your
case. So, they *can* have different alignment requirements, and those
*are* (again) compiler-specific. Please take a look in the
documentation that came with your compiler. There is also the newsgroup
for discussions on VC++, 'microsoft.public.vc.language'. You should
consider posting there as well.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask- Hide quoted text -
- Show quoted text -
thomas said:Fred said:On Nov 13, 11:50 pm, Victor Bazarov <[email protected]>
wrote:thomas wrote:
struct A{
int a;
char b;
};
class B{
int a;
char b;
};
sizeof(A)=6; sizeof(B)=8. why?
Hm... This is probably covered in your compiler documentation.
Try reading it. The Standard does not dictate what the size
should be. It's "implementation-defined".
There is a difference between your types, you know that, yes?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I don't know. I'm using vs2005.
I suppose "struct" and "class" should be equivalent except the
default privilege.
There's no reason to set different padding, if my understanding
is right.- Hide quoted text -
- Show quoted text -Who has a 'this', and who doesn't?
Nobody "has a 'this'" since there are no non-static member
functions. 'this' only exists in that context.
OTOH, IIUIC, the 'struct' is an aggregate and the 'class' isn't in
your case. So, they *can* have different alignment requirements,
and those *are* (again) compiler-specific. Please take a look in
the
documentation that came with your compiler. There is also the
newsgroup
for discussions on VC++, 'microsoft.public.vc.language'. You should
consider posting there as well.
V
Is "this" pointer an issue? The size of the following struct is 1,
which is the same as an empty struct. It confuses me when addressing
the "this" here. Why the function pointer in struct A is not counted
in the struct size is also not clear to me.
struct A{
public:
void f(){}
};
struct A{
int a;
char b;};
class B{
int a;
char b;
};
sizeof(A)=6; sizeof(B)=8. why?
Why not?
(Well, I can think of one big reason why they shouldn't be
different: If the struct really has a size of 6 bytes, you
will be getting memory alignment problems if you eg. use an
array of such structs. Accessing the 'a' member of each other
object in the array will cross a word boundary, which in many
processors will be inefficient because it causes penalty clock
cycles. And this assuming it doesn't cause a bus error, like
in some architectures; but I assume this is on an Intel
processor, so an error won't happen, but an inefficiency may
well happen.)
Fred said:thomas wrote:
struct A{
int a;
char b;
};
class B{
int a;
char b;
};sizeof(A)=6; sizeof(B)=8. why?Hm... This is probably covered in your compiler documentation. Try
reading it. The Standard does not dictate what the sizeshould
be. It's "implementation-defined".
There is a difference between your types, you know that, yes?
I don't know. I'm using vs2005.
I suppose "struct" and "class" should be equivalent except the
default privilege.
There's no reason to set different padding, if my understanding is
right.- Hide quoted text -
- Show quoted text -
Who has a 'this', and who doesn't?
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.