delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/09/08:38:02

From: kagel AT quasar DOT bloomberg DOT com
Date: Thu, 9 May 1996 08:31:00 -0400
Message-Id: <9605091231.AA04826@quasar.bloomberg.com >
To: j DOT aldrich6 AT genie DOT com
Cc: djgpp AT delorie DOT com
In-Reply-To: <199605090327.AA248672446@relay1.geis.com> (j.aldrich6@genie.com)
Subject: Re: more sizeof questions
Reply-To: kagel AT dg1 DOT bloomberg DOT com

   From: j DOT aldrich6 AT genie DOT com
   Date: Thu,  9 May 96 03:15:00 UTC 0000

FORTIN44 AT EELA wrote on 05/08/96  3:45PM

   >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??

   The size of the whole structure may be divisible by 4, but the individual
   fields also have to be word-aligned.  Read on...

   >typedef unsigned char 		BYTE;
   >typedef unsigned short 	WORD;
   >typedef unsigned long		DWORD;

   >typedef struct
   >{
   >    DWORD	VESASignature;			4
   >    WORD	VESAVersion;				2 (+2 padding)

   >    DWORD    	OEMStringPointer;		4
   >    DWORD    	Capabilities; 			4
   >    DWORD    	VideoModePointer;		4
   >    WORD   	TotalMemory;			2 (+2 padding)
   >    BYTE  		Info[236];				236
   >}	_VGAInfoBlock;                             =      256 bytes   (260 with
   internal padding)

j DOT aldrich AT genie DOT com responded on 05/08/96 3:15 UTC

   Each of your 2-byte fields gets another 2 bytes of padding on it, for
   a total of 260.  There IS a workaround, though, in the form of the gcc
   __attribute__ ((packed)) command.  See my last post for details.

Not quite.  Actually, each field does NOT need word-alignment.  Only objects
whose size is >= 4 bytes (long, int, float, long long & double [did I miss
any?]) require word (4byte) address alignment.  The member TotalMemory is not
padded as both it and the char array Info require 2byte alignment.  The extra
two bytes are added at the end of the structure to insure that each element of
an array of _VGAInfoBlock's will each have their first member, VESASignature,
aligned.

-- 
Art S. Kagel, kagel AT quasar DOT bloomberg DOT com

A proverb is no proverb to you 'till life has illustrated it.  -- John Keats

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019