3 ms·
If your language has “low level” integers that can take on exactly 2^n values, all bit patters are numbers, so there is no need to “check whether there is a num
by Someone 9y ago
If your language has “low level” integers that can take on exactly 2^n values, all bit patters are numbers, so there is no need to “check whether there is a number there at all”.
If, in addition, you want implicit conversion from integers to booleans, you have to pick some patterns as meaning ‘false’.
The first is fairly normal in low-level languages. So, the question is why one would want implicit conversion from integer to boolean. The main reasons I can think of are
- because assembly doesn’t have boolean.
- to keep source code shorter.
For C, I think it was a combination of both. Testing for null pointers using if(p) is nicely short. From there, given that there’s little or no difference between pointers and integers at register level, it is a short step to if(i) for integer i.
- vardump 9y ago> because assembly doesn’t have boolean. What is flags register file for then? Zero flag, carry, overflow, etc? They sure look booleans to me. Sometimes assembler routines pass booleans in carry flag.