Promoting an unsigned bit-field

david.f.prosser dfp at cbnewsl.ATT.COM
Tue Jul 18 01:18:13 AEST 1989


In article <12570018 at hpclwjm.HP.COM> walter at 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...



More information about the Comp.std.c mailing list