Remix.run Logo
▲ Panzerschrek 36 minutes ago

-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).

▲ 20 minutes ago | parent | next [-]
[deleted]
▲mrkeen 30 minutes ago | parent | prev [-]

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?

▲Panzerschrek 26 minutes ago | parent [-]

Bool should be logically 1-bit, when stored in memory only least significant bit should be used and the rest is allowed to be garbage. Such approach gives compilers as much room for optimizations as possible. Forcing them writing some specific bit-pattern may lead to suboptimal code generation.