Anyone want to run this through dmc?

Don nospam at nospam.com
Mon Jul 25 15:49:07 PDT 2011


Walter Bright wrote:
> On 7/12/2011 10:11 PM, bcs wrote:
>> I broke down and installed wine:
>>
>> bcs at doors:~/Downloads/dmc$ cat split.cpp
>> #include<stdio.h>
>> struct S0 {
>>    unsigned f1 : 1;
>> };
>>
>> struct S0 s;
>>
>> int main (void) {
>>    int x = -3;
>>    int y = x>= (0, s.f1);
>>    printf ("%d\n", y);
>>    return 0;
>> }
>> bcs at doors:~/Downloads/dmc$ wine dm/bin/dmc.exe split.cpp
>> link split,,,user32+kernel32/noi;
>>
>> bcs at doors:~/Downloads/dmc$ wine split.exe
>> 1
>>
>> seems DMC is broke too, but it's debatable if this test case is of
>> value to DMD.
> 
> I think DMC is correct here.
> 
>    x >= (0, s.f1)
> 
> is typed as:
> 
>   int >= (int, unsigned)
> 
> which is:
> 
>   int >= unsigned
> 
> which does an unsigned compare,
> 
>   0xFFFFFFFD >= 1
> 
> which evaluates to:
> 
>   1
> 

 From a comment on that page:
------
The interpretation turns on how you interpret 6.3.1.1p2:

The following may be used in an expression wherever an int or unsigned 
int may be used:
— An object or expression with an integer type whose integer conversion 
rank is less than or equal to the rank of int and unsigned int.
— A bit-field of type _Bool, int, signed int, or unsigned int.
If an int can represent all values of the original type, the value is 
converted to an int; otherwise, it is converted to an unsigned int. 
These are called the integer promotions. All other types are unchanged 
by the integer promotions.
------
So the unsigned bit field should be promoted to int.

And the simplified case:
     x >= s.f1
should definitely be a signed comparison.
Makes me wonder why signed-ness of bitfields is even allowed.


More information about the Digitalmars-d mailing list