Problems with sizeof function

G

Guest

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:
 

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

Top