www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/09/10:10:39

From: kagel AT quasar DOT bloomberg DOT com
Date: Tue, 9 Jul 1996 10:02:22 -0400
Message-Id: <9607091402.AA11095@quasar.bloomberg.com >
To: locke AT mcs DOT net
Cc: djgpp AT delorie DOT com
In-Reply-To: <31e1ed3d.40380323@news.mcs.net> (locke@mcs.net)
Subject: Re: C/C++ Packing (was: Re: [_dos_]find{first|next} problem!)
Reply-To: kagel AT dg1 DOT bloomberg DOT com

   From: locke AT mcs DOT net (Peter Johnson)
   Date: Tue, 09 Jul 1996 05:29:13 GMT

   On Sun, 07 Jul 1996 19:27:32 GMT, alaric AT abwillms DOT demon DOT co DOT uk (Alaric
   B. Williams) wrote:

   >
   >It seems to be a structure packing problem... the ff.c in djtst claims
   >that the offset of ff_name is 30; but the SAME test in my code returns
   >32. Why is the packing changing? I compile both sources with the same
   >command line!
   >
   Peter Johnson continues:

   Output of compiled ff.c:
   sizeof(ff) = 290
   ff.ff_attrib = 21
   ff.ff_ftime = 22
   ff.ff_fdate = 24
   ff.ff_fsize = 26
   ff.ff_name = 30
   (null): error

   Output of compiled ff.cc (identical to ff.c):
   sizeof(ff) = 292
   ff.ff_attrib = 21
   ff.ff_ftime = 22
   ff.ff_fdate = 24
   ff.ff_fsize = 28
   ff.ff_name = 32
   (null): error

   For some reason, ff_fdate is not packed as a SHORT!!  instead it is
   packed on a 4-byte margin...... HMMM!

   DJ, Charles - Any ideas why packing would differ C/C++??

This is a known bug in GCC handling structure packing in C++.  I believe that
DJ and others have reported it to the FSF and it should be fixed in later
versions.  For now you can add #pragma pack or the __attribute__((packed))
storage attribute to your C++ structures (see the DJGPP docs, GNU C/C++ Manual,
or prior threads for the exact usage as I have not had occasion to use these).
Also the faq (section 22.9) points to:
http://www.delorie.com/gnu/docs/gcc/gcc_83.html#SEC86

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