gcc 中的嵌套函数使用 -std=c99
nested functions in gcc using -std=c99
根据我正在阅读的内容,下面的代码是无效的 c99,但是我似乎能够使用 gcc -std=c99 编译它,据我所知应该禁用允许嵌入功能的 GNU 扩展。我似乎无法弄清楚为什么会这样。
int main() {
int e() {
printf("testing");
return 0;
};
e();
return 0;
}
为了获得关于不一致代码的警告,您还需要使用 -pedantic
标志,然后您将看到以下内容 (see it live):
warning: ISO C forbids nested functions [-Wpedantic]
int e() {
^
要将其变为错误,您可以使用 -Werror
将警告变为错误或使用 -pedantic-errors
.
来自 standards support 上的 gcc 文档:
to obtain all the diagnostics required by the standard, you should also specify -pedantic (or -pedantic-errors if you want them to be errors rather than warnings)
根据我正在阅读的内容,下面的代码是无效的 c99,但是我似乎能够使用 gcc -std=c99 编译它,据我所知应该禁用允许嵌入功能的 GNU 扩展。我似乎无法弄清楚为什么会这样。
int main() {
int e() {
printf("testing");
return 0;
};
e();
return 0;
}
为了获得关于不一致代码的警告,您还需要使用 -pedantic
标志,然后您将看到以下内容 (see it live):
warning: ISO C forbids nested functions [-Wpedantic]
int e() {
^
要将其变为错误,您可以使用 -Werror
将警告变为错误或使用 -pedantic-errors
.
来自 standards support 上的 gcc 文档:
to obtain all the diagnostics required by the standard, you should also specify -pedantic (or -pedantic-errors if you want them to be errors rather than warnings)