www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/10/04/05:06:42

Date: Wed, 4 Oct 1995 09:09:59 +0100
From: nicolas AT JUPITER DOT saclay DOT cea DOT fr (Eric NICOLAS)
To: DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU

To djgpp (or more generally GNU users) users,

I saw some time ago on the list that the attribute packed meant that no
word or dword boundary alignment was performed on the argument. So I
wrote the next definitions :

#define PACKED      __attribute__ ((packed))
typedef short int int16;

struct TDrive
{ int16  Present                PACKED;
  char   Name[12]               PACKED;
};

struct TSetUp
{ char   SystemFontName[21]     PACKED;
  int16  ScreenX,ScreenY        PACKED;
  int16  ScreenColors           PACKED;
  int16  DosVer1,DosVer2        PACKED;
  TDrive Drives[26]             PACKED;
};

The size of TSetUp structure (adding all elements sizes) might be 395 bytes,
but it appears to be 396 1 (in fact a word-boundary alignment is made between
SystemFontName and ScreenX)

Can someone tell me what is the REAL effect of "packed", and what is the good
way to implement a non-aligned structure.

- Raw text -


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