c - gcc 中的嵌套函数使用 -std=c99

标签 c gcc

根据我正在阅读的内容,下面的代码是无效的 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)

关于c - gcc 中的嵌套函数使用 -std=c99,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29108187/

相关文章:

c++ - Makefile——高效编译

c - C 中的位、半字节和移位

c - Q : About reading data files using fscanf()

c - 克服C中缺乏多态性的问题

c++ - 解析 VS2010 MSBuild vcxproj 文件

c++ - 如何在没有运行时成本的情况下基于断言指导 GCC 优化?

c - lseek64 是否会引发任何设备特定的操作?

C 解密声明

c - 为什么某些 C 编译器会在奇怪的地方设置函数的返回值?

c++ - 关于运算符重载和参数相关查找,Visual Studio 10 和 GCC 4.5 之间的哪个编译器是正确的?