Signed bit field represetation
问题 I made a bit field with a field sized 1 bit, and used int instead of unsigned . Later on when i tried to check the value of the field i found that the value was -1. I used this code to check the binary represantation and the value of my bit field: #include <stdio.h> #include <stdlib.h> union { struct { int bit:1; } field; int rep; } n; int main() { int c, k; n.field.bit=1; for (c = 31; c >= 0; c--) { k = n.rep >> c; if (k & 1) printf("1"); else printf("0"); } printf("\n %d \n", n.field.bit);