【发布时间】:2014-02-07 06:33:28
【问题描述】:
#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;
}
使用g++,结果变成4 -2,foo.d怎么会变成-2?
【问题讨论】:
标签: c++ bit-fields