VS C 中的基本运行时检查++ 2010年
我正在将 MSVS2010 用于之前用 C 开发的项目
。我发现调试模式与发布模式存在问题。调试模式给出了我预期的结果,而发布模式给出了错误的结果,并且发布模式产生的结果在所有运行中都不同(方式不同)。
然后,我转到项目属性并打开发布模式的基本运行时检查 (BRC)。如果我将 BRC 设置为“堆栈帧(RTC)”或 RTC1,则结果与调试模式相同。如果我只使用未初始化的变量(RTCu),结果是错误的。
当我打开所有警告时,程序中有3种类型的警告: 1. 将函数 X 替换为函数 X_s(以禁用使用 _CRT_SECURE_NO_WARNINGS) 2. '<':有符号/无符号不匹配。原因是我定义了
#define NO_OF_INPUTS 20
int j;
j = 0;
while (j<NO_OF_INPUTS) //The warning is for this line
{…}
在数据成员“State”之后添加的 4 个字节填充。这是结构:
typedef struct X
{
int State;
double Value;
} XName;
在谷歌上进行一些搜索,我发现了这个: http://msdn.microsoft.com/en- us/library/8wtf2dfz(v=vs.80).aspx
所以我猜填充的东西可能是问题......但不确定
有修复错误的建议吗?如果可能的话,还有其他警告……
最好。
I’m using MSVS2010 for a previous project developed in C.
I see an issue with Debug vs. release mode. The debug mode gives me my expected result while the release mode gives me wrong result and the results produced by release mode are different in all runs (way different).
Then, I went to the project properties and turned on the Basic Runtime Check (BRC) for the Release mode. If I turn set BRC to “Stack Frames (RTCs)” or RTC1 then the result is the same as Debug mode. If I only use Uninitialized variables (RTCu), the result is wrong.
When I turn on all warnings, there are 3 types of warning in the program:
1. Replace a function X by a function X_s (to disable use _CRT_SECURE_NO_WARNINGS)
2. ‘<’: signed/unsigned mismatch. The reason is I defined
#define NO_OF_INPUTS 20
int j;
j = 0;
while (j<NO_OF_INPUTS) //The warning is for this line
{…}
4 bytes padding added after data member ‘State’. Here is the struct:
typedef struct X
{
int State;
double Value;
} XName;
Doing some search on google, I found this:
http://msdn.microsoft.com/en-us/library/8wtf2dfz(v=vs.80).aspx
So I guess the padding stuff may be the thing… Not sure though
Any suggestion to fix the bug? And other warnings if possible…
Best.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎很难给您一个好的提示,因为通常此类问题发生在代码中的某个时刻,程序员做出一些假设(有意或无意),而这些假设不能保证按标准实现(例如内存初始化等)。这种行为也可能是由于对不属于“您的”的内存进行写入/读取而导致的(但在调试模式下,内存已初始化,或者您正在读取/写入程序不需要的一些字节)。
按照您的描述修复警告当然是个好主意。然而,在我看来,这并不一定有帮助。您可以尝试 cppcheck 来获取诸如未初始化内存之类的警告。
如果是内存问题,您可能不会收到编译器警告。在这种情况下,微软(免费)的“应用程序验证器”有时会有所帮助。
如果没有,您应该编写单元测试以更接近问题。无论如何,这是一个好主意......
It seems hard to give you a good hint because usually such problems occur at some point in code where the programmer makes some assumptions (conscious or not) which are not guaranteed to be fullfilled (like memory initialization etc.) by the standard. Such behaviour can also result from writing/reading to/from memory that is not "yours" (but in Debug mode the memory was initialized or you're reading/writing some bytes that are not required by the program).
It's certainly a good idea to fix warnings as you described them. However, it seems to me like this will not necessarily help. You could try cppcheck to get warnings like uninitialized memory.
If it is a memory problem, you may not get compiler warnings. In this case Microsofts (free) "Application Verifier" can sometimes help.
If it doesn't, you should write unit tests to get closer to the problem. It's a good idea anyways...