Bitfield 공간 최적화
C++·2026.11.03
구조체에서 정수 필드 뒤에 : n으로 비트 크기를 지정할 수 있는데 각 필드가 필요한 자리만큼 할당하여 공간을 절약할 수 있다.위의 예시에서 딱 1+3+4 = 8비트에 맞춰지니 해당 구조체의 크기는 1바이트다. struct ExampleBitField { bool a: 1; unsigned char b: 3; unsigned char c: 4;};struct Example { bool a; unsigned char b; unsigned char c;};int main() { ExampleBitField exb{true, 5, 12}; Example ex{true, 5, 12};/* movzx eax, BYTE PTR [rbp-1] ..