It will not compile.
I added return 0; at the end of main() to remove the second problem with -Wall -Werror . If you do this, you will see:
$ gcc -Wall -Werror costest1.c -o costest -lm costest1.c:5:1: error: conflicting types for 'cos'
This is not done at compile time because math.h also defines a function called cos . Please note that the prototype for cos :
double cos(double x);
not
float cos(float x);
If you did not include math.h , you could compile but get:
$ gcc -Wall -Werror costest1.c -o costest -lm costest1.c:5:1: error: conflicting types for built-in function 'cos' [-Werror] costest1.c: In function 'main': costest1.c:13:3: error: implicit declaration of function 'sin' [-Werror=implicit-function-declaration] costest1.c:13:32: error: incompatible implicit declaration of built-in function 'sin' [-Werror] cc1: all warnings being treated as errors
This is because cos not a normal function, but is treated as builtin . As you can see, this is defined in terms of sin . If cos was a normal function, you might see a duplicate character error.
In C, you cannot have two functions with the same name, even if they have different arguments. In C ++, you can, in that the same named methods can differ in calling parameters (but not only with return type).
source share