logoalt Hacker News

Panzerschrek • today at 1:49 PM • 3 replies • view on HN

-1 is not -1 for different sizes of integers. Which exact -1 do you want? 32-bit? 64-bit? int-sized (as int is defined in current implementation)? With current approach it's simple, boolean type is expected to have 1-bit size (which is rounded to 8 bits if stored in memory).


Replies

rep_lodsb • today at 3:02 PM

If bool was a signed 1-bit type (i.e. having possible values of either 0 or -1), it could be extended to any size, same as an integer?

Of course we can't have that now, because unsigned bool is baked into the C language standard, and even into processors (x86 SETcc instruction). While "char" being signed or not is still implementation-defined IIRC...

➕ show 1 reply
mrkeen • today at 1:54 PM

You have some expectations of the size of the bool (it's simply 1 bit but also 8 bits.)

What expectations do you have of the value?

➕ show 1 reply