I have the following code in my program:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int print_numbers_above(double x, float y, int z)
{
printf("x=%lf, y=%f, z=%d\n", x, y, z);
}
int main()
{
double x = 1.25;
float y = 1.25;
int z = 3;
print_numbers_below(x, y, z);
print_numbers_above(x, y, z);
return 0;
}
int print_numbers_below(double x, float y, int z)
{
printf("x=%lf, y=%f, z=%d\n", x, y, z);
}
Output:
x=1.25, y=0.000000, z=Garbage
x=1.250000, y=1.250000, z=3
Now, I know that the function print_numbers_below() should have been declared earlier (or should have been defined before main). But it doesn't throw an error. It assumes it to be an extern function (and since it is returning int, there isn't any conflict of return types). Now, I fail to understand why can't I pass more than 1 argument correctly?
(I'm using Visual Studio 2013)
A reasonable compiler would give you the following error:
foo.c:12:5: warning: implicit declaration of function 'print_numbers_below' is invalid in C99 [-Wimplicit-function-declaration]
print_numbers_below(x, y, z);
^
foo.c:16:5: error: conflicting types for 'print_numbers_below'
int print_numbers_below(double x, float y, int z)
^
foo.c:12:5: note: previous implicit declaration is here
print_numbers_below(x, y, z);
^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With