https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122312
Bug ID: 122312
Summary: static local (nested) functions
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
It would be nice to have static nested functions, which would be like regular
static functions, but scoped (just like static local variables).
They would be unable to use automatic variables from the parent.
alx@devuan:~/tmp$ cat nested.c
int
main(void)
{
int x = 42;
// static int y = x; // error: initializer element is not constant
static int z = 7;
static int f(void)
{
// return x; // error: parent variable is not static
return z;
}
}
alx@devuan:~/tmp$ gcc -Wall -Wextra nested.c -Wno-unused
nested.c: In function ‘main’:
nested.c:8:20: error: invalid storage class for function ‘f’
8 | static int f(void)
| ^