开发者

why BOOLEAN of winapi uses 1 for true and 2 for false?

开发者 https://www.devze.com 2023-04-09 18:08 出处:网络
I didn\'t know. just saw it in my debug window a BOOLEAN from STORAGE_DEVICE_DESCRIPTOR wasresolving to 2 instea开发者_运维技巧d of of 1. I got panicked thinking 2 means false. then I realized its 1 f

I didn't know. just saw it in my debug window a BOOLEAN from STORAGE_DEVICE_DESCRIPTOR was resolving to 2 instea开发者_运维技巧d of of 1. I got panicked thinking 2 means false. then I realized its 1 for true. But why this kind of odd design ? Or I am doing something wrong in my side ? never heard of anything like multibyte boolean. (BTW I am using MinGW and Qt Creator IDE's Debugger)


There are historical reasons for why many types of boolean exist which is discussed here. Essentially any non-zero values are true, and zero is false. This means you shouldn't do comparisons like so:

if( x == TRUE )

But instead:

if( x )
0

精彩评论

暂无评论...
验证码 换一张
取 消