Defining function within a function in C [duplicate]
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.
精彩评论