Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cwjcc!tut.cis.ohio-state.edu!att!cbnewsl!dfp From: dfp@cbnewsl.ATT.COM (david.f.prosser) Newsgroups: comp.std.c Subject: Re: Promoting an unsigned bit-field Message-ID: <1138@cbnewsl.ATT.COM> Date: 17 Jul 89 15:18:13 GMT References: <12570018@hpclwjm.HP.COM> Reply-To: dfp@cbnewsl.ATT.COM (david.f.prosser) Organization: AT&T Bell Laboratories Lines: 32 In article <12570018@hpclwjm.HP.COM> walter@hpclwjm.HP.COM (Walter Murray) writes: >It's been a while since we talked about promotion rules, so here's >an easy question for the experts. > >What is the result of applying the integral promotion to an unsigned >int bit-field that is narrower than an int? > >Specifically, what value is returned by the following function? > > int f (void) > { > struct {unsigned int b : 3;} s = {7}; > return s.b/-1; > } > >In other words, does s.b get promoted to int or to unsigned int? The wording is not extremely clear in the pANS since bit-field is not effectively a type. The only evidence on the Committee's intent for this issue are statements such as following from the Rationale, section 3.2.1.1. The unsigned preserving rules greatly increase the number of situations where unsigned int confronts signed int to yield a questionably signed result, whereas the value preserving rules minimize such confrontations. Given these sorts of statements, the intent is that the size of the bit- field is taken into account. In the above example, the promoted type of s.b would be int, and a signed division should occur. Dave Prosser ...not an official X3J11 answer...