I just debugged a C program for a long time, only to find that I missed an argument when making a function call, so junk instead filled the missing argument. Stupid mistakes like this are really frustrating, but I suppose compilers should be able to detect this. (C doesn't even support default arguments; even in C++, default arguments need to be explicitly declared.)
Update: The prototype was found to be wrong, too...
So, is there a GCC flag for warning unmatched function call argument number? I always have -Wall
and -pedantic
on; it's quite surprising that such an obvious error goes undetected. (Actually I suppose there is some reason that GCC does not report, but I can't think of any at this time.)
Embarrassing code example:
static void dfs();
int main(int argc, const char *argv[]) {
dfs(1);
}
static void
dfs(int remain, int last) {
// dfs
}
Another discovery I just made is that if the prototype contains argument, the compiler will report; but the prototype happened to contains no arguments, then the compiler just slipped.