delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/30/23:11:47

Message-Id: <199903310411.XAA09206@delorie.com>
Comments: Authenticated sender is <mert0407 AT sable DOT ox DOT ac DOT uk>
From: "George Foot" <george DOT foot AT merton DOT ox DOT ac DOT uk>
To: "Andrew Davidson" <andrew AT lemure DOT freeserve DOT co DOT uk>
Date: Wed, 31 Mar 1999 05:09:17 +0000
MIME-Version: 1.0
Subject: Re: How does DJGPP store its structs?
CC: djgpp AT delorie DOT com
X-mailer: Pegasus Mail for Win32 (v2.42a)
Reply-To: djgpp AT delorie DOT com

On 31 Mar 99 at 4:00, Andrew Davidson wrote:

> I've tested the structs and all stuff done from within C code works fine.
> Is this 12 byte thing the result of the way I'm trying to use the scratch
> struct (from within another struct) or just a limitation of djgpp? I have a
> feeling that djgpp might be trying to optimise the struct  so is there any
> way I can dissable this optimisation while keeping all the other forms of
> optimisation available?

gcc is padding the structs with dead space to align the fields 
for speed.  To tell it not to do this, put `__attribute__ 
((__packed__))' after the struct definition, or if the code is 
C++, put it after every field in the struct.  In both cases, it 
goes before the semicolon.

C example:

    struct foo {
        char a;
        int b;
    } __attribute__ ((__packed__));
    
C++ example:

    struct bar {
        char a __attribute__ ((__packed__));
        int b __attribute__ ((__packed__));
    };

The C++ way works in C too, but it's more hassle.

-- 
George

- Raw text -


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