Xref: news2.mv.net comp.os.msdos.djgpp:3698 From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: more sizeof questions Date: Thu, 9 May 1996 10:52:13 +0100 Organization: The University of York, UK Lines: 30 Message-ID: References: <199605090048 DOT UAA09442 AT eelab DOT newpaltz DOT edu> NNTP-Posting-Host: tower.york.ac.uk Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII In-Reply-To: <199605090048.UAA09442@eelab.newpaltz.edu> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp On Wed, 8 May 1996, John Fortin wrote: > OK, I'm a bit confused..(nothing new i'm afraid)... The structure > below was taken from the VESA 1.2 spec. sizeof(_VGAInfoBlock) should > be 256. DJGPP gives 260. What's up with this. A previous posting > mentioned 4 byte boundaries, but 256 is divisable by 4. Any Ideas?? > > typedef struct > { > DWORD VESASignature; 4 > WORD VESAVersion; 2 > DWORD OEMStringPointer; 4 The OEMStringPointer is 32 bits, but follows a 16 bit value. This would put it at a non-dword address, so gcc adds two bytes between the two. Normally this is a Good Thing (makes your code faster). If you are working with an already specified structure (eg. the VESA spec) it is a pain, and you have to add __attribute__ ((packed)) after each of your variables. btw. this is one good reason not to dump structures into files just by calling fwrite(&struct, sizeof(struct). It's tempting to do, but it tends to break code when you move from one compiler to another... /* * Shawn Hargreaves. Why is 'phonetic' spelt with a ph? * Check out Allegro and FED on http://www.york.ac.uk/~slh100/ */