delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/09/30/20:57:23

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: packed data structures?
Date: Mon, 30 Sep 1996 18:10:53 -0700
Organization: Three pounds of chaos and a pinch of salt
Lines: 33
Message-ID: <32506F9D.552D@cs.com>
References: <52nl1a$kqv AT news2 DOT cnct DOT com>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp211.cs.com
Mime-Version: 1.0
To: John Panettiere <jmarco AT cnct DOT com>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

John Panettiere wrote:
> 
> Hello, all.
> 
> At first I didn't know why my VBE2 code wasn't working, but then I
> realized that djgpp wasn't packing the data structures - so I browsed
> the info files and found "__attribute__((packed))", which seemed to be
> the answer I was looking for.  I applied this attribute to every field
> in all of my VBE2 data structures, but the problem still seemed to
> remain - 16 bit fields were being padded!  Is there a known problem
> with packing, or is there something I'm overlooking?

Only if you are using C++, in which case there is a bug in the gcc
compiler that prevents the __attribute__((packed)) keyword from
working.  The workaround is to surround the struct definition with

#pragma pack(1)
...
#pragma pack()

BTW, this is in the FAQ, section 22.10.

-- 
John M. Aldrich <fighteer AT cs DOT com>                      

* Anything that happens, happens.
* Anything that, in happening, causes something else to happen,
  causes something else to happen.
* Anything that, in happening, causes itself to happen again, happens
  again.
* It doesn't necessarily do it in chronological order, though.
 
                                       --- Douglas Adams

- Raw text -


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