typedef struct { bool a: 1; bool b: 1; bool c: 1; bool d: 1; bool e: 1; bool f: 1; bool g: 1; bool h: 1; } __attribute__((__packed__)) not_if_you_have_enough_booleans_t;
boolean bloat
I first thought you wrote boolean float, not sure if that’s even worse.
boolean root beer float
deleted by creator
The 8-bit Intel 8051 family provides a dedicated bit-addressable memory space (addresses 20h-2Fh in internal RAM), giving 128 directly addressable bits. Used them for years. I’d imagine many microcontrollers have bit-width variables.
bit myFlag = 0;
Or even return from a function:
bit isValidInput(unsigned char input) { // Returns true (1) if input is valid, false (0) otherwise return (input >= '0' && input <= '9'); }
We could go the other way as well: TI’s C2000 microcontroller architecture has no way to access a single byte, let alone a bit. A Boolean is stored in 16-bits on that one.
And, you can have pointers to bits!
if wasting a byte or seven matters to you, then then you need to be working in a lower level language.
It’s far more often stored in a word, so 32-64 bytes, depending on the target architecture. At least in most languages.
No it isn’t. All statically typed languages I know of use a byte. Which languages store it in an entire 32 bits? That would be unnecessarily wasteful.
std::vector<bool>
fits eight booleans into one byte.auto v = std::vector<bool>(8); bool* vPtr = v.data; vPtr[2] = true; // KABOOM !!!
I’ve spent days tracking this bug… That’s how I learned about bool specialisation of std::vector.
I mean is it really a waste? What’s minimum amount of bits most CPUs read in one cycle.
We need to be able to express 0 and 1 as integers so that functionality is just being overloaded to express another concept.
Wait until the person who made this meme finds out about how many bits are being wasted on modern CPU architectures. 7 is the minimum possible wasted bits but it would be 31 on every modern computer (even 64b machines since they default to 32b ints).
pragma(pack) {
int a:1, b:1, … h:1;
}
IIRC.
Joke’s on you, I always use 64 bit wide unsigned integers to store a 1 and compare to check for value.
So does the cpu
just like electronic components, they sell the gates by the chip with multiple gates in them because it’s cheaper
That’s a good analogy.
7 Shades of Truth
Wait till you realise the size of SSD sectors
…or you can be coding assembler - it’s all just bits to me