GCC标志提高运行时错误捕捉? [英] GCC flags to improve run-time error catching?

查看:120
本文介绍了GCC标志提高运行时错误捕捉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将一个Linux C ++应用程序移植到了Windows(通过Visual Studio 2010 C ++ express)。在这个过程中,我注意到Windows可执行文件倾向于在我的代码中发现微妙的错误,导致程序崩溃。但是,相同的代码和bug似乎在Linux / GCC中不被注意到,并且该程序将继续愉快地运行。我在过去试图移植的程序中看到过这种行为。我的代码中的一个示例bug是通过1个元素传递一个数组。



我可以使用哪些标记来改进GCC中的运行时错误捕获?当我遇到最轻微的运行时错误时,我希望我的程序像Windows版本一样不稳定。或者这是否依赖于操作系统,并且不在用户的控制范围之内? 一个示例在我的代码中的错误是通过1个元素传递数组。


Valgrind通常很容易检测到这样的错误。我建议你在怀疑这样的错误时总是在Valgrind下检查你的代码 - 这将在调试过程中节省大量时间。


I've recently ported a Linux C++ application to Windows (via Visual Studio 2010 C++ express). In the process I've noticed the Windows executable tends to pick up on subtle bugs in my code, crashing the program. But the same code and bug seems to go unnoticed in Linux/GCC and the program will continue running happily. I've seen this behaviour in past programs I tried to port. An example bug in my code is writing pass an array by 1 element.

What flags can I enable to improve run-time error catching in GCC? I want my program to be as volatile as the Windows version when it encounters the slightest run-time bug. Or does this depend more on the OS and is out of the user's control?

解决方案

An example bug in my code is writing pass an array by 1 element.

Bugs like this are usually easily detected by Valgrind. I would suggest you to check your code under Valgrind always when you suspect bugs like this - it will save a lot of time during debugging.

这篇关于GCC标志提高运行时错误捕捉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆