logoalt Hacker News

bjackman • today at 1:13 PM • 3 replies • view on HN

'bool' is still at least 1 byte in C. If you want to store one Boolean per bit you have to manually implement a bitmap.


Replies

viega • today at 1:51 PM

A bool does automatically cast to an unsized bit slice.

Meaning, if you have a struct and you want to bit-pack your booleans, you can declare each one as, say, uint8_t some_bool : 1;

You may then do `x.some_bool = true;` etc.

It's a small nicety to avoid bitwise operators, anyway.

tyromaniac • today at 1:20 PM

Or pull out the C++ and use std::vector<bool>,... But you should probably never do that

➕ show 1 reply
ReDress • today at 1:30 PM

[dead]