From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: Bit fields in djgpp Date: Thu, 15 Jan 1998 00:31:55 -0800 Organization: Alcyone Systems Lines: 37 Message-ID: <34BDC97B.5453B8F8@alcyone.com> References: NNTP-Posting-Host: newton.alcyone.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Noam Rotem wrote: > 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. The results you get a correct. You have declared the bitfields in question as signed, and for a 1 bit signed field, the only possible values are 0 and -1. Assigning 1 to a 1 bit signed field results in automatic conversion, and so Test.x gets the value -1. If you wanted them to really be "bits" (0 or 1) in the traditional sense, you should have declared the bitfields unsigned. -- Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com Alcyone Systems / http://www.alcyone.com/max/ San Jose, California, United States / icbm://+37.20.07/-121.53.38 \ "Life may be / the product of imperfections." / (Marclo Gleiser)