C++ 对于未签名的long,使用true超过true是一种坏习惯吗

C++ 对于未签名的long,使用true超过true是一种坏习惯吗,c++,C++,我已经见过很多次这个习惯,比如说下面的代码: void GetCurrentState(unsigned long bState); 我是这样用的: GetCurrentState(true); GetCurrentState(1); GetCurrentState(TRUE); GetCurrentState(anynumber); 应该是这样的: GetCurrentState(true); GetCurrentState(1); GetCurrentState(TRUE); G

我已经见过很多次这个习惯,比如说下面的代码:

void GetCurrentState(unsigned long bState);
我是这样用的:

GetCurrentState(true);
GetCurrentState(1); 
GetCurrentState(TRUE);
GetCurrentState(anynumber);
应该是这样的:

GetCurrentState(true);
GetCurrentState(1); 
GetCurrentState(TRUE);
GetCurrentState(anynumber);

是的,在我看来,用数字来表示布尔值是一种糟糕的编程实践

对于没有布尔类型的语言来说,这种做法是一种古老的做法

布尔数据类型将有助于防止程序可能传递除1以外的值以表示true,并对1而不是零进行比较的问题


所以,如果必须的话,请遵守遗留代码。提升布尔类型,您将得到奖励(代码中的缺陷更少)

我猜名称
bState
意味着它应该是一个布尔值?为什么是
无符号长
呢?为什么要使用
bool
类型的值
true
来初始化
无符号长
?它们是不同的数据类型!另一个提示,代码< >真< /代码>代码>定义< /COD> >真不是C++的一部分。这是一些库中的一个定义。@ Frand Windows SDK不是标准C++。