#include <iostream>
#include <stdint.h>
struct Foo
{
int a : 2;
int b : 2;
int c : 2;
int d : 2;
};
int main()
{
Foo foo;
foo.d = 2;
std::cout << sizeof(foo) << std::endl;
std::cout << foo.d << std::endl;
return 0;
}
Using g++, the result turns to be 4 -2
, how could foo.d became -2?