www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/14/12:47:13

From: kagel AT quasar DOT bloomberg DOT com
Date: Fri, 14 Jun 1996 12:40:33 -0400
Message-Id: <9606141640.AA05096@quasar.bloomberg.com >
To: caldweg1 AT tipo DOT transcripts DOT com
Cc: lav AT video DOT yars DOT free DOT net, djgpp AT delorie DOT com, j DOT aldrich6 AT genie DOT com
In-Reply-To: <9605148347.AA834773242@tipo.transcripts.com> (caldweg1@tipo.transcripts.com)
Subject: Re: Re[2]: How are bool's allocated?
Reply-To: kagel AT dg1 DOT bloomberg DOT com

   Errors-To: postmaster AT ns1
   From: caldweg1 AT tipo DOT transcripts DOT com
   Date: Fri, 14 Jun 96 10:25:04 est
   Content-Type: text
   Content-Length: 126

	     I had this problem - porting code that had bools to djgpp -
	     v2. Use unsigned name : 1; and life is good.

Right but, IMHO, the compiler will allocate a long to hold this bit and I do
not know if multiple declarations will be placed into a single word unless the
bit fields are all in the same struct.  Putting all of the bit fields into a
struct, however, does place the fields in contiguous locations, ie 32bits of
bit fields in the first word with the 33rd bit in the next word, assuming no
single field spans the word boundary.  Hence:

struct allbools {
    unsigned char truth1:1;
    unsigned char truth2:1;
    unsigned char truth3:1;
    unsigned char truth4:1;
    unsigned char truth5:1;
    unsigned char truth6:1;
    unsigned char truth7:1;
    unsigned char truth8:1;
    unsigned char truth9:1;
} MyBools;

OR 

struct allbools4 {
    unsigned int truth1:1;
    unsigned int truth2:1;
    unsigned int truth3:1;
    unsigned int truth4:1;
    unsigned int truth5:1;
    unsigned int truth6:1;
    unsigned int truth7:1;
    unsigned int truth8:1;
    unsigned int truth9:1;
} MyBools4;

BTW: The structure MyBools takes up 2 bytes while MyBools4 takes up 4 bytes.

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