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

cur*_*ous 1 c gcc

从我正在阅读的下面的代码是无效的c99,但我似乎能够使用gcc -std = c99编译它,据我所知,应该禁用允许嵌入式功能的GNU扩展.我似乎无法弄清楚为什么会这样.

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

    e();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Sha*_*our 5

为了获得有关不符合代码的警告,您还需要使用该-pedantic标志,然后您将看到以下内容(请参见实时):

warning: ISO C forbids nested functions [-Wpedantic]
 int e() {
 ^
Run Code Online (Sandbox Code Playgroud)

要将此变为错误,您可以使用-Werror将警告变为错误或-pedantic-errors.

从关于标准支持的gcc文档:

要获得标准所需的所有诊断,您还应指定-pedantic(或-pedantic-errors,如果您希望它们是错误而不是警告)