I came across the following situation:
Ubuntu 16.01
gcc --version
gcc (GCC) 6.3.0 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
test.c
main() {
printf("Hello Word.\n");
printf("pow function : %f \n", pow(10,2));
}
Use this command to compile:
gcc -std=c11 test.c -o test
test.c:3:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
main() {
^~~~
test.c: In function ‘main’:
test.c:4:3: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
printf("Hello Word.\n");
^~~~~~
test.c:4:3: warning: incompatible implicit declaration of built-in function ‘printf’
test.c:4:3: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
test.c:5:35: warning: implicit declaration of function ‘pow’ [-Wimplicit-function-declaration]
printf("powf function : %d \n", pow(10,2));
^~~
test.c:5:35: warning: incompatible implicit declaration of built-in function ‘pow’
test.c:5:35: note: include ‘<math.h>’ or provide a declaration of ‘pow’
And I ran the generated file:
./test
Hello Word.
pow function : 100.000000
I ask: Am I required to do #include <stdio.h>
and #include <math.h>
? this applies to all standard library ?
File changed:
#include <stdio.h>
#include <math.h>
int main() {
printf("Hello Word.\n");
printf("powf function : %f \n", pow(10,2));
return 0;
}
Command to compile (in this case you do not have warnings):
gcc -std=c11 test.c -o test
Output:
./test
Hello Word.
pow function : 100.000000
In both cases the output is the same.