当你遇到错误时,首先检查一下 [英] First things you check for when you've got errors

查看:56
本文介绍了当你遇到错误时,首先检查一下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我在程序中出错时,无论是编译错误,还是b $ b链接器错误,或者程序在运行时崩溃,我都有一个列表

我最初检查的东西。


如果我收到未申报的错误,我要做的第一件事是通过

通过我的头文件,并检查包含保护宏是否是特定于该头文件的
。例如,如果头文件是名为data.h的
,我确保包含守卫是H__DATA。而不是

类似于H__GUI的东西。我必须检查这个的原因是我通常将一个头文件中的包含警卫复制粘贴到另一个头文件中。


程序我是目前正在开发中运行时崩溃,

错误是无效的内存访问。我逐行完成了违规的

功能,不久之后我就发现了这个错误。我有一个强烈的习惯,即写下以下内容:


char * p = data;

char const * const pover =数据+大小的数据;


这种习惯非常强烈,它让我写道:


unsigned * p = data;

unsigned const * const pover = data + sizeof data;


....当然我应该写:+ sizeof data / sizeof * data


所以我接下来要做的是找一个sizeof在每个

文件中,以确保我在其他地方没有犯同样的错误。


你最初检查什么样的东西当出现

a某种错误?我发现有一件事很有帮助,关闭

隐式int以及通过编译器隐式函数声明

选项。


Martin


When I have errors in a program, whether they be compiler errors,
linker errors, or if the program crashes when running, I have a list
of things I check for initially.

If I get an error for something undeclared, the first thing I do is go
through my header files and check that the inclusion-guard macro is
specific to that header file. For instance, if the header file is
called "data.h", I make sure the inclusion guard is "H__DATA" and not
something like "H__GUI". The reason I have to check for this is that I
commonly copy-paste inclusion guards from one header file to another.

The program I''m currently developing was crashing when running, the
error being an invalid memory access. I went through the offending
function line-by-line and it wasn''t long before I spotted the error. I
have a strong habit of writing the following:

char *p = data;
char const *const pover = data + sizeof data;

This habit was so strong that it led me to write:

unsigned *p = data;
unsigned const *const pover = data + sizeof data;

....when of course I should have written: + sizeof data/sizeof*data

So next thing I did was do a find for "sizeof" in every one of the
files to make sure I hadn''t made the same error elsewhere.

What kind of things do you all check for initially when presented with
a certain kind of error? One thing I find helps greatly is turning off
implicit int and also implicit function declarations via the compiler
options.

Martin

推荐答案

Martin Wells< wa **** @ eircom.netwrites:
Martin Wells <wa****@eircom.netwrites:

当你出现

a某种错误时,你最初检查了什么样的东西?
What kind of things do you all check for initially when presented with
a certain kind of error?



您是在谈论语法错误类型诊断吗?当我查看编译器引用的源代码
代码行时,通常会出现这种错误的原因。

Are you talking about syntax error type diagnostics? Usually the
cause of that kind of error is obvious when I look at the source
code line cited by the compiler.


我发现的一件事有很大帮助,即通过编译器选项关闭隐式int和

也是隐式函数声明。
One thing I find helps greatly is turning off implicit int and
also implicit function declarations via the compiler options.



打开很多警告可以提供帮助,但我建议一直使用

它们,而不仅仅是当你''试图找到一些

特定的源代码错误。

-

Ben Pfaff
http://benpfaff.org


2007年10月6日星期六08: 56:37 -0700,Martin Wells写道:
On Sat, 06 Oct 2007 08:56:37 -0700, Martin Wells wrote:

我正在开发的程序在运行时崩溃,

错误正在无效的内存访问。我逐行完成了违规的

功能,不久之后我就发现了这个错误。我有一个强烈的习惯,即写下以下内容:


char * p = data;

char const * const pover =数据+大小的数据;


这种习惯非常强烈,它让我写道:


unsigned * p = data;

unsigned const * const pover = data + sizeof data;


...当然我应该写:+ sizeof data / sizeof * data
The program I''m currently developing was crashing when running, the
error being an invalid memory access. I went through the offending
function line-by-line and it wasn''t long before I spotted the error. I
have a strong habit of writing the following:

char *p = data;
char const *const pover = data + sizeof data;

This habit was so strong that it led me to write:

unsigned *p = data;
unsigned const *const pover = data + sizeof data;

...when of course I should have written: + sizeof data/sizeof*data



不会和数据+ 1做同样的事情吗?

-

Army1987(替换NOSPAM)用电子邮件)

一个汉堡包总比没有好。

没有比永恒的幸福更好的了。

因此,汉堡包更好而不是永恒的幸福。

Wouldn''t &data + 1 do the same thing?
-
Army1987 (Replace "NOSPAM" with "email")
A hamburger is better than nothing.
Nothing is better than eternal happiness.
Therefore, a hamburger is better than eternal happiness.


Martin Wells写道:
Martin Wells wrote:

当我在程序中出错时,无论是编译器错误,还是b $ b链接器错误,或者程序在运行时崩溃,我都有一个列表

我最初检查的东西。
When I have errors in a program, whether they be compiler errors,
linker errors, or if the program crashes when running, I have a list
of things I check for initially.



这取决于错误......

对于运行时错误,有些是很难找到的。如果在测试

环境中发生故障,则在调试器中运行程序很容易。有些错误不会在调试器中发生,或者无法再现。在这种情况下,我会使用验尸调试器。


对于加密软件,我不允许调试生产
环境。因此,除非可以在TEST中重现错误,否则需要

才能阅读来源。


在某些情况下,你没有来源。我能记住

嵌入式ROM软件中的一个这样的错误,我们通过查看二进制文件找到它,然后

告知供应商有关该错误的信息。

-

Tor< torust [at] online [dot] no>


"构建软件设计的方法有两种。一种方法是

使它变得如此简单以至于显然没有任何缺陷。而另一种方式是让它变得如此复杂以至于没有明显的

缺陷

It depends on the error...

For run-time errors, some are hard-to-find. If fault happened in test
environment, running the program in debugger is easy. Some bugs don''t
happen in the debugger, or can''t be reproduced. In such cases, I would
use a post-mortem debugger.

For cryptographic software, I''m not allowed to debug the production
environment. Hence, unless the error can be reproduced in TEST, one need
to read the source.

In some cases you don''t have the source. I can remember one such bug in
embedded ROM software, which we located by looking at the binary, and
informed the vendor afterwards about the bug.
--
Tor <torust [at] online [dot] no>

"There are two ways of constructing a software design. One way is to
make it so simple that there are obviously no deficiencies. And the
other way is to make it so complicated that there are no obvious
deficiencies"


这篇关于当你遇到错误时,首先检查一下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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