Q: My compiler is complaining about an invalid redeclaration of a function, but I only define it once and call it once.
A: Functions which are called without a declaration in scope, perhaps because the first call precedes the function's definition, are assumed to be declared as if by:
extern int f();That is, an undeclared function is assumed to return int, and to accept an unspecified number of arguments (though there must be a fixed number of them and none may be ``narrow''). If the function is later defined otherwise, the compiler complains about the discrepancy. Functions returning other than int, or accepting any ``narrow'' arguments, or accepting a variable number of arguments, must all be declared before they are called. (And it's by all means safest to declare all functions, so that function prototypes can check that arguments are passed correctly.)
Another possible source of this problem is that the function has the same name as another one declared in some header file.
See also questions 11.3 and 15.1.
K&R1 Sec. 4.2 p. 70
K&R2 Sec. 4.2 p. 72
ISO Sec. 188.8.131.52
H&S Sec. 4.7 p. 101