【发布时间】:2019-01-06 13:01:04
【问题描述】:
这段代码是未定义的行为吗?
特别是这个? "while (Thing* x = getNext(x))" 是因为标准中的规则而将 x 初始化为零,还是只是幸运,或者编译器无论如何都在这样做,但不应该依赖?
#include <iostream>
struct Thing {
};
Thing* getNext(Thing* thing)
{
std::cout << "thing:" << thing << "\n";
return thing;
}
void test()
{
while (Thing* x = getNext(x))
{
}
}
【问题讨论】:
标签: c++ variables undefined-behavior