小编emp*_*rai的帖子

为什么 Valgrind 不检测未初始化变量的使用?

据我了解,当代码包含未初始化变量的使用时,Valgrind 应该报告错误。在下面的玩具示例中,printer未初始化,但程序“愉快”地打印了消息。

#include <iostream>

class Printer {
    public:
        void print() {
            std::cout<<"I PRINT"<<std::endl;
        }
};


int main() {
    Printer* printer;
    printer->print();
};
Run Code Online (Sandbox Code Playgroud)

当我用 Valgrind 测试这个程序时,它没有报告任何错误。

这是预期的行为吗?如果是的话,为什么会这样?

c++ debugging valgrind

1
推荐指数
1
解决办法
1280
查看次数

标签 统计

c++ ×1

debugging ×1

valgrind ×1