How to catch strange undefined behaviour in C++ code?

倖福魔咒の 提交于 2019-12-01 18:40:07

On ubuntu, I like to run with valgrind (http://valgrind.org/).

sudo apt-get install valgrind
valgrind ./mypgrogram

It doesn't report all issues, but when it does, it will report the nature and origin.

Also recommended:

valgrind --db-attach=yes ./myprogram

Which allows you to debug (backtrace, inspect) and continue the program when a violation/uninitialized memory reference is detected.

On some older Ubunti I had to use sudo to make valgrind be able to attach gdb:

sudo -E valgrind --db-attach=yes ./myprogram

If tr1/unordered_map should be quite trivial to replace with std::unordered_map

E.g. with a quick hack

#include <unordered_map>

namespace std { namespace tr1 {

    using std::unordered_map;
    using std::hash;
    // etc...
} }

Of course this is not good practice, and you might just want to typedef between std::unordered_map and std::tr1::unordered_map instead, but in the interest of quick checks...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!