【发布时间】:2020-10-20 11:04:54
【问题描述】:
我正在尝试对开源 C++ 项目进行一些更改。 我知道C++中BOOL的值在声明的时候应该初始化,否则会出人意料。但是几乎所有源代码中的布尔变量都是这样声明的未初始化
bool oracle_pro_decl;
bool _oracle_external_procedure;
bool _oracle_language_procedure;
我使用 GNU C++ 作为编译器,有没有办法将 bool 的所有默认值设置为 false?
【问题讨论】:
-
are uninitialized declared like this它们是否在文件范围中声明? -
是的,它们是在头文件中声明的。
-
你可能知道错了。考虑阅读good C++ programming book,然后查看this C++ reference
-
I know that the value of BOOL in C++ should be initialized when declared, otherwise it will be unexpected不精确。未初始化的变量将具有不确定的值。但是有些情况下变量是默认初始化的。at head files什么是“头部填充物”?在file scope 定义的标识符有static storage duration 和zero initialized。