(Update below)
At the time of writing this, the Mozilla Coding Style guidelines have this recommendation under “General C/C++ Practices”:
Don’t put an else right after a return. Delete the else, it’s unnecessary and increases indentation level.
I can appreciate this in some circumstances, such as when checking for an error case early in a long function:
void f()
{
[...]
Everyone knows that global variables are bad and should be avoided wherever possible. Why? Because each global variable is, in effect, an implicit argument to every function that can see the global variable. The same thing is true of any non-local state.
And the presence of non-local state means that you can’t reason locally about your [...]
Posted in C, Correctness, Valgrind on March 13th, 2009 1 Comment »
Here’s what sounds like a simple question: in C, what’s the best way to convert a string representing an integer to an integer?
The good way
One way is to use the standard library function called strtol(). There are a number of similar functions, such as strtoll() (convert to a long long) and strtod (convert to a [...]
Posted in Correctness, Valgrind on February 27th, 2009 5 Comments »
(For those who don’t want to read a long post, here’s the short version: if you use Valgrind, make sure you learn about the –track-origins=yes option that was added to version 3.4.0, it will make your life easier.)
Earlier this week, Jesse Ruderman reported a problem found with the Valgrind tool Memcheck:
==56620== Conditional jump or move [...]
Posted in Correctness on February 27th, 2009 Comments Off
People often use the word “bug”. Unfortunately it’s a very imprecise word. “Error” suffers from the same problems. Both of them are used at different times to mean incorrect program code, incorrect program states, and visibly incorrect program behaviour. The conflation of these distinct things inhibits clear thinking and can mask [...]