Xref: news2.mv.net comp.os.msdos.djgpp:2552 From: fnunez AT cs DOT uct DOT ac DOT za (Fabian Nunez) Newsgroups: comp.os.msdos.djgpp Subject: Re: SIZEOF disparity...? Date: 9 Apr 1996 07:48:06 GMT Organization: University of Cape Town Lines: 67 Message-ID: <4kd4nm$1je@groa.uct.ac.za> References: NNTP-Posting-Host: unagi.cs.uct.ac.za To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In Mike 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