简体   繁体   English

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

[英]nested functions in gcc using -std=c99

From what I am reading the below code is invalid c99, however I seem to be able to compile it using gcc -std=c99 which, to my knowledge should disable the GNU extension that allows for embedded functions. 从我看下面的代码是无效的c99,但是我似乎能够使用gcc -std = c99对其进行编译,据我所知,应该禁用允许嵌入功能的GNU扩展。 I cannot seem to figure out why this is the case. 我似乎无法弄清楚为什么会这样。

int main() {
    int e() {
        printf("testing");
        return 0;
    };

    e();
    return 0;
}

In order to get warnings on non-conformant code you need to use the -pedantic flag as well, then you will see the following ( see it live ): 为了获得关于不合格代码的警告,您还需要使用-pedantic标志,然后您将看到以下内容( 实时查看 ):

warning: ISO C forbids nested functions [-Wpedantic]
 int e() {
 ^

To turn this into an error you can use -Werror to turn warnings into errors or -pedantic-errors . 要将其转换为错误,可以使用-Werror将警告转换为error或-pedantic-errors

From the gcc docs on 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) 要获得标准要求的所有诊断,还应该指定-pedantic(如果希望它们是错误而不是警告,则应指定-pedantic-errors)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM