Hello - I'm having this problem in VC++.NET:
For the following struct:
typedef struct _Tran
{
short trndelflag;
short trnrectype;
unsigned long trnpatnum;
unsigned long trnseqnum;
unsigned long trnadmit;
unsigned long trndscharge;
unsigned long trnloc1;
unsigned long trnloc2;
char trncod1[4];
char trncod2[4];
char trncod3[4];
char trnsecurity;
char trnstorage;
} TRAN;
If you add up the individual members' sizes, you get 42: either by the book or by computing sizeof(TRAN.trndelflag) + sizeof( TRAN.trnrectype ) + ...etc.
However, sizeof( TRAN ) returns 44!? At first I thought this had something to do with the alignment or whatever, but with any other structure I tried, sum( sizeof( members )) is ALWAYS = sizeof( struct ).
Even in this struct, if you change trncod1[4] to trncod1[2], you get both sizes = 40.
What's going on? Thanks...
For the following struct:
typedef struct _Tran
{
short trndelflag;
short trnrectype;
unsigned long trnpatnum;
unsigned long trnseqnum;
unsigned long trnadmit;
unsigned long trndscharge;
unsigned long trnloc1;
unsigned long trnloc2;
char trncod1[4];
char trncod2[4];
char trncod3[4];
char trnsecurity;
char trnstorage;
} TRAN;
If you add up the individual members' sizes, you get 42: either by the book or by computing sizeof(TRAN.trndelflag) + sizeof( TRAN.trnrectype ) + ...etc.
However, sizeof( TRAN ) returns 44!? At first I thought this had something to do with the alignment or whatever, but with any other structure I tried, sum( sizeof( members )) is ALWAYS = sizeof( struct ).
Even in this struct, if you change trncod1[4] to trncod1[2], you get both sizes = 40.
What's going on? Thanks...