int main() {
int f(int a, int b) {
return a+b;
}
return f(2,3);
}
Compilation using GCC.
u@x1 ~/Desktop> gcc -std=c99 -pedantic -o a a.c
a.c: In function ‘main’:
a.c:2:2: warning: ISO C forbids nested functions [-Wpedantic]
int f(int a, int b) {
^
u@x1 ~/Desktop> ./a ; echo $status
5
u@x1 ~/Desktop>
clang does not support nested functions; this is a complex feature which is infrequently used, so it is unlikely to be implemented anytime soon. In C++11 it can be emulated by assigning lambda functions to local variables.
Motivation
Adding support for nested functions would simplify the grammar and allow the TopLevelDecl special case to be removed, as functions would be considered regular declarations (see issue #38).
Example source file containing nested functions.
Compilation using GCC.
Clang has intentionally omitted support for nested functions:
Adding support for nested functions would simplify the grammar and allow the
TopLevelDecl
special case to be removed, as functions would be considered regular declarations (see issue #38).