Mail Archives: djgpp/1996/04/09/05:07:55
In <Pine DOT A32 DOT 3 DOT 92 DOT 960406153743 DOT 75628A-100000 AT acs5 DOT acs DOT ucalgary DOT ca> Mike <mbwarren AT acs DOT ucalgary DOT ca> writes:
Hi Mike
>what am i doing wrong:
nothing :)
>with djgpp v2, when i take the sizeof this struct:
>typedef struct
>{
> char magic[2];
> long size;
> int dummy;
> long offset;
>} header_t;
>it returns 16, when it should return 14 (2 chars = 2 + long (4) + int (4)
>+ lont (4) = 2+4+4+4=14)
In DJGPP (and other C compilers I've used) items in a struct are aligned
on a 4-byte boundary for performance reasons. So in reality you have:
typedef struct
{
char magic[2];
char padding[2]; /* added by DJGPP, not accessible by your code */
long size;
int dummy;
long offset;
} header_t;
In fact, if you made (say) the "dummy" element a char instead of an int
you'll find sizeof(header_t) is still 14 (DJGPP will insert 3 padding bytes).
>(BTW, why are int's represented as 4 bytes on a PC? sizeof(int) returns
>4...)
DJGPP chooses to use dwords for ints. There is a command-line switch to use
16 bit ints, but I can't remember what it's called (it's in the info docs)
>i am using djgpp v2 on a 486-33 w/4megs ram...
>(if this is in the FAQ, sorry, but i can't use www/ftp; our DNS server is
>down...)
>------------. mailto:mbwarren AT acs DOT ucalgary DOT ca .--------------
>.___ ___. | o _ | ? |"a smoking
>| \/ | | /\, (*) '\o__ o | section in a
>| i K E | | .(*)>(*)______'(*)\_____./'\.|\_________. | resturant is
>| | | | Gateway to the TEMPLE OF MIKE +---+ | like a peeing
>|__|\/|__| | `-.----------------------------------.--' | | section in a
>w a r r e n | | http://www.ucalgary.ca/~mbwarren +------+ | swimming pool"
>------------' `----------------------------------' '\.____________
Interesting quote - how graphic ;)
Hope that helps
Fabian
--
Fabian Nunez, Bsc(hons) student, University of Cape Town
email:fnunez AT cs DOT uct DOT ac DOT za web:http//www.cs.uct.ac.za/~fnunez
----------------------------------------------------------------
"k3wl aRe th3 lAmErz, 4 thEy sh4ll RulE!" - from the ElitE Bible
- Raw text -