c++ release和debug编译后的结果不一致

来源:互联网 发布:dnz端口 编辑:程序博客网 时间:2024/05/29 16:15

最近遇到一个问题,c++ release和debug编译后的结果不一致,查了好久才查到原因。

    bool init(const string& datrie_file, const string& encoder_file)
    {
        SegmentorImpl_::init(datrie_file, encoder_file);
    }

奇怪的是对于debug编译,每次运行时init函数的返回值都是true

而对于release版本, 每次运行时的返回结果却是false。

把代码修改正确后就好了。

    bool init(const string& datrie_file, const string& encoder_file)
    {
        return SegmentorImpl_::init(datrie_file, encoder_file);
    }


后续:

有这样一个case, void* ptr 在堆中申请一个一段内存空间,但是使用时存在ptr[-1]的情况,而这么使用也并非每次都会有段错误发生。

0 0
原创粉丝点击