我正在尝试运行这段简单的代码
#include <stdio.h>
int main(){
hello();
}
void hello(){
printf("Hello");
}使用
gcc -std=gnu11 main.c在Mac上没有成功。我得到了
error: implicit declaration of function 'hello' is invalid in C99 这是我的gcc版
% gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin你能帮我理解一下这里发生了什么吗?
发布于 2021-08-13 05:11:17
error: implicit declaration of function 'hello' is invalid in C99
在调用函数之前声明或定义函数,例如
#include <stdio.h>
void hello(){
printf("Hello");
}
int main(){
hello();
}编辑:尽管诊断显示为C99 (我从未为此而烦恼过,但也许这只是一个小错误?)可以通过检查应设置为201112L的__STDC_VERSION__宏来检查C11支持。这可以像这样检查:
#if (__STDC_VERSION__<201112L)
#error C11 support needed
#endif或者(如果_Static_assert可用)
_Static_assert(__STDC_VERSION__>=201112L, "C11 or higher needed");https://stackoverflow.com/questions/68767004
复制相似问题