这个问题出现在问题答案的评论中.当类型转换为int时,C/C++ bool类型总是保证为0或1吗?
有问题的代码在bool不初始化其值的情况下分配(本地)数组.
const int n = 100;
bool b[n];
Run Code Online (Sandbox Code Playgroud)
显然,价值观b是不确定的.
一些评论者认为阅读b[0]是不明确的行为.这是在C++标准中的任何地方陈述的吗?我仍然相信相反:
显然存储已分配,并且基本bool类型的初始化已完成,因为它没有构造函数.因此,它肯定与取消引用未初始化的指针或在未初始化的非平凡对象上调用方法/强制转换操作符不同.标准似乎涵盖了这些具体案例.
C中的行为确实未定义:C中声明的未初始化变量会发生什么?它有价值吗?一些受访者似乎对这两者感到困惑.
在最新的C++ 0x草案中,我找不到不确定值的定义,尤其是没有允许访问这样的值来触发处理器陷阱的定义.事实上,Bjarne的Stroustrup的是不知道的inderminate值可能是什么:http://zamanbakshifirst.blogspot.com/2007/02/c-indeterminate-value.html
我几次被这个问题所困扰,所以我的同事也是如此.编译时
#include <deque>
#include <boost/algorithm/string/find.hpp>
#include <boost/operators.hpp>
template< class Rng, class T >
typename boost::range_iterator<Rng>::type find( Rng& rng, T const& t ) {
return std::find( boost::begin(rng), boost::end(rng), t );
}
struct STest {
bool operator==(STest const& test) const { return true; }
};
struct STest2 : boost::equality_comparable<STest2> {
bool operator==(STest2 const& test) const { return true; }
};
void main() {
std::deque<STest> deq;
find( deq, STest() ); // works
find( deq, STest2() ); // C2668: 'find' : ambiguous call to …Run Code Online (Sandbox Code Playgroud) 我已经编写了 LLDB 数据格式化程序,但无法在 Xcode lldb 控制台中显示日志输出。数据格式化程序示例创建记录器并对其进行写入,如下所示:
def __init__(self, valobj, dict):
logger = lldb.formatters.Logger.Logger()
...
logger >> "Providing synthetic children for a vector named " + str(valobj.GetName())
Run Code Online (Sandbox Code Playgroud)
我这样做了,并使用命令启用了 lldb 格式化程序日志
log enable -g lldb formatters
Run Code Online (Sandbox Code Playgroud)
当我打印一个变量(例如使用frame var x)时,我确实看到了很多调试输出,但不是我的。