C++: Is it possible to condense `bool` objects within the same byte?
You can use bitfields. Works with Repl.it's gcc version 4.6.3.
#include <iostream>
struct Test
{
bool a:1;
bool b:1;
bool c:1;
bool d:1;
bool e:1;
bool f:1;
bool g:1;
bool h:1;
//bool i:1; //would increase size to 2 bytes.
};
int main()
{
Test t;
std::cout << sizeof(t) << std::endl;
return 0;
}