bitfield signedness

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

This program:

#include <stdio.h>
int main() {
        struct { unsigned a : 27; } s = { 1 };
        printf("%d\n", s.a < -1);
        printf("%d\n", ((unsigned)s.a) < -1);
}

generates as output:
0
1

This is unexpected to me, because the field 'a' is already unsigned, so
adding an extra cast to unsigned shouldn't change anything. Using the
compiler flags -f{no-}{un}signed-bitfields doesn't have any effect.

I've tried this same program with different compilers: clang gives the
same output as gcc, vs10 generates output "1 1".

Is this a bug in gcc (or vs)? Or does the C-standard not specify the
required behavior? Is there any way to change the behavior of gcc (so
make it output "1 1")?

Thanks.

Wouter


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux