delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/29/07:00:33

Xref: news2.mv.net comp.os.msdos.djgpp:4333
From: Enrico Horn <enrico DOT horn AT prakinf DOT tu-ilmenau DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Bit field problem. Help!
Date: Tue, 28 May 1996 10:56:54 +0200
Organization: Technische Universitaet Ilmenau
Lines: 34
Message-ID: <31AABFD6.27D0@prakinf.tu-ilmenau.de>
References: <4o3ihi$k54 AT aphex DOT direct DOT ca>
NNTP-Posting-Host: ipisparc4.prakinf.tu-ilmenau.de
Mime-Version: 1.0
To: jasonk AT direct DOT ca
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jason Keddie wrote:
> 
> I'm porting some BC4 stuff over to DJGPP and when I declare a bit
> field like this
> 
> struct
>   Life {
>            unsigned neighbours : 4;
>            unsigned alive : 1;
>            unsigned onTheList : 1;
>            unsigned : 2;
>           };
> 
> It takes up 4 bytes instead of 1. I've tried using -mno-bit-align but
> it gives me an error like invalid option or something like that. I
> need it to take up only 1 byte. Any help greatly appreciated.

Yes, right. DJGPP aligns data structure elements depending on its size,
that means: byte on byte boundaries, word on 16bit boundaries, dword on
32bit boundaries. So every of your elements is aligned on a byte
boundary.
I think thats because on 32bit pmode its even faster, you get a run
time penalty on unaligned access. But theres a way out: look at the
DJGPP-FAQ (sizeof question or similar). You have to add something like
__attribute__((packed)) (sorry, dont know the exact syntax).
Hope that helps,
Enrico.

-- 
/---------------------------------------------------------------------\
|Enrico Horn               Tel. 036738/41929                          |
|07426 Lichta              E-mail: enrico DOT horn AT prakinf DOT tu-ilmenau DOT de  |
|Ortsstrasse Nr. 14        http://www.prakinf.tu-ilmenau.de/~ehorn    |
\---------------------------------------------------------------------/

- Raw text -


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