C标准(ANSI [C89],C99,C11)中不允许嵌套函数(块作用域中的函数声明).
但我无法在C标准中找到它.
编辑:
为什么函数定义不能在函数定义中(复合语句)?
函数声明和函数定义之间存在差异.声明仅声明函数的存在,定义定义函数.
int f(void) { /* ... */ } // function definition
int f(void); // function declaration
Run Code Online (Sandbox Code Playgroud)
在6.9.1中,函数的语法定义为
function-definition: declaration-specifiers declarator declaration-list opt compound-statment
在6.8.2中,您可以将复合语句中的内容定义为声明或声明.函数定义不被认为是这些语法中的任何一个.
所以是的,函数声明在函数中是合法的,但函数定义不是例如
int main(int argc, char*argv[])
{
int f(void); // legal
int g(void) { return 1; } ; // ILLEGAL
// blah blah
}
Run Code Online (Sandbox Code Playgroud)