I was reading a book on GCC. It said only the standard library is linked by default for any C program. Since the pow() is not in the standard library, I will have to link to it using the -lm flag. However, when I compiled, I simply used:
gcc hello.c -o hello
and it still worked..
And there is another similar problem, the book also said that if you have printf("%f\n", 4); in your C program and if you compile WITHOUT -Wall option, no warning will be issued. However, I tried compiling it without the -Wall option but I still got a warning:
hello.c:6:2: warning: format ‘%f’ expects argument of type ‘double’,
but argument 2 has type ‘int’ [-Wformat]
Why is this? The book said I have to supply -lm and -Wall in order to make my program compiled and get the warning but I did not use either of them but I still got my program compiled and got the warning?
Thank you!
GCC supplies several standard library functions as built-ins:
If you look at the list of built-ins, you’ll see that
powis one of them.If you add
-fno-builtinto your compiler options, you should get the linker error that you’re expecting.