开发者

Defining function within a function in C [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Are nested functions a bad thing in gcc ?

As far as I know, C does not allow a function to be defined within other function. But the following code compiles and runs without any error in gcc. Can someone explain the reason why? See this also : http://ideone.com/AazVK

#include <stdio.h>

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

int main()开发者_JAVA百科
{       
        void val2(int x) {
                x = x*10;
                val1(x);

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

        val2(20);

        return 0;
}


gcc (but not g++) supports nested functions as a C language extension.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜