sHi!
I have a very strange problem with the behaviour of the sizeof command. I
have tested it in vc6,vc 2001 and vc 2003. The problem is quite simple.
When I made a sizeof to the next struct, it returns that the size is 40
instead of 38. I consider that a short is 2 bytes, float 4 bytes, unsigned
long 4 byte, unsigned short 2 bytes. If i add all the size of the fields it
must be 38 but sizeof says that is 40.
The struct is the next:
typedef struct
{
short est;
short numbe1;
float dst;
float Line;
unsigned long tmp;
float tmp1;
float tmp2;
unsigned long tck;
unsigned long tl;
unsigned short dp;
unsigned short ldact;
unsigned short lnc;
}test;
If I remove one unsigned short field, the size change to 36, but if made
size of (unsigned short) it return 2.
This is the other "crazy" struct:
typedef struct
{
short est;
short numbe1;
float dst;
float Line;
unsigned long tmp;
float tmp1;
float tmp2;
unsigned long tck;
unsigned long tl;
unsigned short dp;
unsigned short ldact;
}test;
I'm getting crazy, any idea??
Thank you very much for your help.
The structure is the next:
Cholo Lennon - 02 Nov 2007 14:18 GMT
This is a common question. Take a look to:
http://groups.google.com/group/microsoft.public.vc.language/browse_frm/thread/8e
7400441b97eb1e/72c336cb677db72c?lnk=gst&q=struct+s
izeof#72c336cb677db72c
Regards
--
Cholo Lennon
Bs.As.
ARG
> sHi!
>
[quoted text clipped - 49 lines]
>
> The structure is the next:
Mark Salsbery [MVP] - 02 Nov 2007 19:45 GMT
You may want to read the "Remarks" section here as well:
http://msdn2.microsoft.com/en-us/library/83ythb65(VS.80).aspx
Mark

Signature
Mark Salsbery
Microsoft MVP - Visual C++
> sHi!
>
[quoted text clipped - 50 lines]
>
> The structure is the next: