C Programming help .....wtf ?!?!
Vu Pham
vu
Tue Jan 25 15:27:31 PST 2005
> -----Original Message-----
> From: linux-users-bounces at linux-sxs.org
> [mailto:linux-users-bounces at linux-sxs.org] On Behalf Of Ben Duncan
> Sent: Tuesday, January 25, 2005 2:16 PM
> To: Linux tips and tricks
> Subject: Re: C Programming help .....wtf ?!?!
>
> Why does the sizeof( struct _dummymenu) on the below return 8 ?
>
>
> typedef struct _dummymenu
> {
> char d_char ;
> int d_sumnumber ;
> } DummyMenu ;
>
> Yet if I do one a structure like this:
>
> typedef struct _dummymenu
> {
> char a_char ;
> char b_char ;
> char c_char ;
> } DummyMenu ;
>
> it returns 3 ......
>
I think because of the memory aligmnet option of the compiler. You can try
#pragma pack(n) to change the default alignment, like
#pragma pack(1) // set the alignment to 1, all vars are adjacent to each
other
typedef struct _dummymenu
{
char d_char ;
int d_sumnumber ;
} DummyMenu ;
Vu
More information about the Linux-users
mailing list