Me deparei com a seguinte situação:
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 este comando para compilar:
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’
E executei o arquivo gerado:
./test
Hello Word.
pow function : 100.000000
Pergunto: eu sou obrigado a fazer o #include <stdio.h>
e #include <math.h>
? isso vale para todas standard library?
Arquivo alterado:
#include <stdio.h>
#include <math.h>
int main() {
printf("Hello Word.\n");
printf("powf function : %f \n", pow(10,2));
return 0;
}
Comando para compilar (neste caso não tem warnings):
gcc -std=c11 test.c -o test
Saida:
./test
Hello Word.
pow function : 100.000000
Nos dois casos a saída é a mesma.