Node:different type arg, Next:too few parameters..., Previous:...undeclared (first use in this function), Up:...undeclared (first use in this function)
You might get this warning if you mismatch a parameter to printf
and a conversion specifier. For example, the following code:
#include <stdio.h> /* To shorten example, not using argp */ int main() { int my_int = 5; printf ("%f", my_int); return 0; }
produces the folliwing warning:
wrongtype2.c: In function `main': wrongtype2.c:6: warning: double format, different type arg (arg 2)
The %f
conversion specifier requires a floating-point argument,
while my_int
is an integer, so GCC complains.
Note: GCC is quite lenient about type mismatches and will
usually coerce one type to another dynamically without complaining,
for example when assigning a floating-point number to an integer.
This extends to mismatched parameters and conversion specifiers --
although you may receive odd results from printf
and so on, the
causes of which may not be obvious. Therefore, in order to generate
this warning, the -Wall
option of GCC was used. This option
causes GCC to be especially sensitive to errors, and to complain about
problems it usually ignores. You will often find the -Wall
option to be useful in finding tricky problems. Here is the actual
command line used to compile this program:
gcc -Wall -o wrong wrongtype2.c