delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/13/09:58:06

Date: Tue, 13 Jan 98 16:42:02 PST
From: Noam Rotem <nrotem AT johnbryce DOT co DOT il>
Subject: Bit fields in djgpp
To: djgpp AT delorie DOT com
Message-ID: <Chameleon.980113164922.nrotem@netvision.netvision>
MIME-Version: 1.0

Hello,

When I use bit fields within a struct, initialize them and 
print the values, I get undefined non zero values.

For example:

struct
  {
  int x : 1;
  int y : 1;
  int z : 1;
  }Test={0,0,0};

main()
  {
  ....
  Test.x=1;
  printf("%d",Test.x);
  ...
  }

I usually get -1 as an output, or other non zero values.

I can live with non zero undefined values, but I would like 
to know the reason for the results I get. Should I declare 
bit fields as unsigned? char? something else? Should I use 
other format then "%d" for printing it?

---------------------------------------------
Noam Rotem
John Bryce Training Centre
Tel Aviv, Israel.
03-7535803
=============================================
1. Take upon yourself an impossible mission.
2. Accomplish the mission.
3. Go back to step 1.

It's the only sane answer to modern life.

---
13/01/98
16:42:02

- Raw text -


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