-Wall -Werrorsometimes it won't help:
On another day and in another file I coded:class X {
public:
typedef enum {
ERR1,
ERR2
} IOErrorCode;
const char* IOstrerror(IOErrorCode c); // string describing the error
};
struct S {
// ...
X::IOErrorCode status;
};
and when I ran the program I would get a segfault at line (*) and GDB was indicating that the stack was partially smashed! Niice!struct S* res = malloc(sizeof(struct S));
if(! DoSomeIO(res))
printf("IO/Error: %s (%d)\n", \
X::IOErrorCode(res->status), res->status);//(*)
After scratching my head for half an hour it occured to me that I made a mistake: I coded
IOErrorCode(res->status) // BAADinstead of
IOstrerror(res->status) // OKThe former is [in C++] a typecast to type IOErrorCode and will cause a crash inside printf().
The latter is a function call.
Ha! Not paying attention to my own code! And I had this sequence in five places handling I/O errors!
This is the most dangerous kind of error as one hits this code path infrequently (sometimes it only happens at a client's site thus driving the client mad).
-ulianov