mewmew/uc

parser: Add support for nested functions (GNU extension)

mewmew opened this issue · 2 comments

Example source file containing nested functions.

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 has intentionally omitted support for nested functions:

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).

Code generation for nested functions is considered a future ambition of this project. Closing this issue for now.

We should add more labels to this issue, I like the developing rainbow 🌈