|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
test.c 的代码
- #include <stdlib.h>
- int main() {
- char ts[] = "132";
- int ti = atoi(ts);
- printf("%i\n", ti);
- }
复制代码
终端输入:gcc test.c -o test
然后成功编译,我执行了./test结果也是对的
那他的提示信息是什么意思?stdlib里不是有stdio了吗,还有我用devc++的话它会直接报错
提示信息如下
- PS E:\C> gcc test.c -o test
- test.c: In function 'main':
- test.c:6:5: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
- printf("%i\n", ti);
- ^~~~~~
- test.c:6:5: warning: incompatible implicit declaration of built-in function 'printf'
- test.c:6:5: note: include '<stdio.h>' or provide a declaration of 'printf'
- test.c:2:1:
- +#include <stdio.h>
- test.c:6:5:
- printf("%i\n", ti);
- ^~~~~~
复制代码
对于这个问题,原因可能是编译环境或编译器设置不同。
在某些情况下,编译器会为某些函数隐式包含它们的头文件,如GCC编译器在某些情况下可能会隐式地包含 <stdio.h> ,所以在你的情况下,尽管没有显式包含 <stdio.h> , printf 函数依然可以正常工作。不过,这种行为并不是所有编译器都会有,也可能会受编译器版本或设置的影响。因此,通常推荐在使用库函数时显式包含其头文件,这样可以确保代码的移植性。
至于你在洛谷(Luogu)上编译没有问题,可能是因为他们的编译环境或设置允许这种隐式包含行为。但是这不意味着这是一种良好的编程习惯,显式包含你正在使用的所有库的头文件,可以避免潜在的编译问题,提高代码的可读性和可移植性。
|
|