在C语言中定义函数内的函数

6

可能重复:
嵌套函数在gcc中是否是一件坏事?

据我所知,C语言不允许在其他函数中定义函数。但是下面的代码在gcc中编译和运行时没有任何错误。有人能解释一下原因吗?也可以参考这个链接:http://ideone.com/AazVK

#include <stdio.h>

void val1( int x ) 
{
        void sig( int x ) {
                printf("%d\n",x*10);
        }
        sig(x);
}

int main()
{       
        void val2(int x) {
                x = x*10;
                val1(x);

                printf( "%d\n", x ); 
                if ( x < 10000 ) {
                        val2(x);                
                }
        }

        val2(20);

        return 0;
}

1
大量重复,例如https://dev59.com/sXA85IYBdhLWcg3wHv3B - Paul R
2
添加-pedantic标志以启用标准模式,这样在使用GNU扩展时就会收到警告。 - Christoph
1个回答

11

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接