Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!pacbell!sorinc!magik From: magik@sorinc.UUCP (Darrin A. Hyrup) Newsgroups: comp.lang.c Subject: Re: Bitfields and printf() Message-ID: <9002200717.AA05176@sorinc.UUCP> Date: 20 Feb 90 08:17:49 GMT References: <9002141141.AA04972@sorinc.UUCP> <660076@hpclwjm.HP.COM> Reply-To: magik%sorinc@PacBell.COM (Darrin A. Hyrup) Followup-To: poster Lines: 42 In article <660076@hpclwjm.HP.COM> walter@hpclwjm.HP.COM (Walter Murray) writes: >Darrin A. Hyrup writes: > >> I have a curious question regarding using bitfields and printing the >> values contained in them via the printf() function. Say we have the >> following definitions: > >[Describes problem with the following] > >> long bit1 : 10; /* range = -512 to +511 */ >> unsigned long bit2 : 10; /* range = 0 to 1023 */ > >Chances are, you compiler is treating 'bit1' as unsigned. Try >explicitly declaring it to be 'signed long'. > >For greater portability (and to be ANSI-legal), stick to 'signed int' >and 'unsigned int' for your bit-fields, and don't rely on whether >the high-order bit of a "plain" int bit-field will be treated >as a sign bit. Thanks for all the letters folks. The problem seems to be in the compiler itself, rather than in what I was doing with it. The documentation clearly states that the compiler does support unsigned and signed bitfields, and that unsigned bitfields may be specified with or without the "signed" keyword. After testing all this out, that has been proven to be incorrect. (Chances are that the manual may have been written with future features in mind or something). I was hoping that it was a problem is just not using the correct conversion switch in the printf() routine, but after the series of tests I made, it is certain that the compiler is not allowing signed bitfields as documented. However, now that I know this I can take the proper steps. (And no, this is not a PC compiler, its the mainframe at work.) Again, thanks for all your help. Darrin Hyrup -- Darrin A. Hyrup // AMIGA Enthusiast rencon!esfenn!dah magik@sorinc.PacBell.COM \X/ & Software Developer pacbell!sorinc!magik ========================================================================== "Speak little and well, if you wish to be considered as possessing merit."