473,503 Members | 7,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

First things you check for when you've got errors


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

Oct 6 '07 #1
14 1744
Martin Wells <wa****@eircom.netwrites:
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.
One thing I find helps greatly is turning off implicit int and
also implicit function declarations via the compiler options.
Turning on lots of warnings can help, but I'd recommend using
them all the time, not just when you're trying to find some
particular source code error.
--
Ben Pfaff
http://benpfaff.org
Oct 6 '07 #2
On Sat, 06 Oct 2007 08:56:37 -0700, Martin Wells wrote:
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
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.

Oct 6 '07 #3
Martin Wells wrote:
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.
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"
Oct 6 '07 #4
"Martin Wells" <wa****@eircom.netwrote in message
>
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.
If a program segfaults that generally means that an array index or size has
been calculated incorrectly. The way that usually happens is that you have
two structures, one of which holds indices into the second. The second
structure is then revised, but the first not updated. So that's always my
first focus.

If you are good about always either destroying or setting invalid pointers
to null you will only occasionally get a sefault due to a wild pointer.
Normally you'll get a null pointer dereference, which is easy to find.

However if you get a really difficult bug, with wrong output popping up
seemingly from nowhere, probably it is due to a pointer pointing into memory
that you own but have reallocated for another purpose.

The important thing is to get to the bottom of a bug as soon as it crops up.
Not just make some change and breathe a sigh of relief when the problem goes
away. If it isn't obvious how the change fixed the bug, put it back and try
to reproduce the bug, and then track it down.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Oct 6 '07 #5
In article <11**********************@w3g2000hsg.googlegroups. com>,
Martin Wells <wa****@eircom.netwrote:
>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.
When I get an error for something undeclared, usually I just
add "int i;" at the top of the procedure.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Oct 6 '07 #6
Army1987:
...when of course I should have written: + sizeof data/sizeof*data

Wouldn't &data + 1 do the same thing?

Good thinking. Only thing is that there's no implicit conversion from:

unsigned (*)[N]

to:

unsigned *

But I might start using:

unsigned const *const pover = (void*)(data+1);

Martin

Oct 6 '07 #7
Martin Wells <wa****@eircom.netwrites:
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.
[...]

If I found myself running into that kind of error frequently,
I'd (a) define a consistent convention for inclusion guard macro
names, where the macro name is mechanically derivable from the file
name, (b) write a tool that examines a header file (or optionally
traverses a directory tree containing header files) and reports any
inconsistencies, and (c) invoke the tool automatically, either as
part of the build process or as part of the process that packages
the software for release.

The directory traversal, of course, can't be done in portable
standard C. If I wanted to insist on implementing the tool in
portable standard C, I'd feed it a list of file names (though it
probably would still have to know how to extract the file name
portion of a full path). But in practice, I'd write it in Perl.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Oct 6 '07 #8
Keith Thompson wrote:
Martin Wells <wa****@eircom.netwrites:
>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.
[...]

If I found myself running into that kind of error frequently,
I'd (a) define a consistent convention for inclusion guard macro
names, where the macro name is mechanically derivable from the file
name, (b) write a tool that examines a header file (or optionally
traverses a directory tree containing header files) and reports any
inconsistencies, and (c) invoke the tool automatically, either as
part of the build process or as part of the process that packages
the software for release.

The directory traversal, of course, can't be done in portable
standard C. If I wanted to insist on implementing the tool in
portable standard C, I'd feed it a list of file names (though it
probably would still have to know how to extract the file name
portion of a full path).
Or perhaps make use of the 'basename' utility?

Oct 6 '07 #9
On Sat, 06 Oct 2007 11:50:43 -0700, Martin Wells wrote:
Army1987:
...when of course I should have written: + sizeof data/sizeof*data

Wouldn't &data + 1 do the same thing?


Good thinking. Only thing is that there's no implicit conversion from:

unsigned (*)[N]

to:

unsigned *

But I might start using:

unsigned const *const pover = (void*)(data+1);
You mean (void *)(&data + 1) ?
--
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.

Oct 7 '07 #10
On Oct 7, 4:56 am, Martin Wells <war...@eircom.netwrote:
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.
I read the error messages

Oct 7 '07 #11
Army1987:
unsigned const *const pover = (void*)(data+1);

You mean (void *)(&data + 1) ?

Wups yeah you're right.

Martin

Oct 7 '07 #12
Old Wolf:
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.

I read the error messages

ERROR: IsBigCan undeclared

Which part of your (unpretentious) genius tells you exactly what you
did wrong?

Is it naivety or attempted-show-off-ness that makes you post such
tripe? Or are you just a dickhead maybe?

Martin

Oct 7 '07 #13
On 7 Oct, 23:31, Martin Wells <war...@eircom.netwrote:
Old Wolf:
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.
I read the error messages

ERROR: IsBigCan undeclared

Which part of your (unpretentious) genius tells you exactly what you
did wrong?

Is it naivety or attempted-show-off-ness that makes you post such
tripe? Or are you just a <deletedmaybe?
most compilers tell you which line the error is on. So go
and look at the line. I'd guess there was a mismatch between
the declaration and usage of IsBigCan. Either a spelling
mistake (it was supposed to be isBigCan). Or you missed it
out completely.

Normally compilers tell you pretty clearly what is wrong,
why not just fix it?

Do you always react that badly to criticism?
--
Nick Keighley

Oct 8 '07 #14
Nick:
most compilers tell you which line the error is on. So go
and look at the line. I'd guess there was a mismatch between
the declaration and usage of IsBigCan. Either a spelling
mistake (it was supposed to be isBigCan). Or you missed it
out completely.

Normally compilers tell you pretty clearly what is wrong,
why not just fix it?

Do you always react that badly to criticism?

I hardly started this thread to deal with simple misspelling errors.
There are many kinds of error which the compiler won't point you to
the problematic line, particularly in the case of macro expansion.
Also, if you get an "undeclared" error, the compiler won't tell you if
one of your inclusion guards is wrong.

Martin

Oct 8 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1388
by: Steven Bethard | last post by:
You probably don't. ;) Here's a script that generates (almost) all of the proposals so far. Don't worry, there's only 1224 that are both not currently valid syntax and also easily greppable. ;) ...
2
1472
by: John Bailo | last post by:
I just went to an Indigo Roadshow meeting at the University of Washington. It was a very clear, clean informative presentation. Indigo is really good stuff -- it's a new layer that lets people...
0
1026
by: Sonya Ayala | last post by:
X-Priority: 3 X-MSMail-Priority: Normal -------=134_0850_7V350V86.96VK945W Content-Type: text/html; Content-Transfer-Encoding: quoted-printable ...
4
1455
by: Theodore H. Smith | last post by:
OK, so I've invented a new data structure, used for look up tables (AKA "map" or "dictionary"), which is much faster, and uses less RAM, than the popular hashing algorithms. I've written a...
4
9266
by: ahaupt | last post by:
Hi all, I'm trying to get a null value into a sql money field through a SqlCommand in c#. However, I get this lovely message (which sparks loads of happy emotions in this overworked body): ...
2
1944
by: Jeff Brown | last post by:
Hi, I suspect that this isn't possible, but I figured I'd ask. My project has a root namespace, let's say it's "Root", that applies to almost every source file (which is why I've set it as the...
8
10441
by: Kappucino XL | last post by:
Good Morning My Very Experienced Developers... I need to place checkboxes for every record in a combobox. I also need to generate a report for only those records CHECKED... I'm still a trainee...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.