I just realized a function may be defined inside another function in C:
void main(){
int foo(){ return 2; };
printf("%d\n", foo());
}
Besides being a neat trick, the useful thing about this is that the inner function is private to the outer function. But… is that a good enough reason to do this in a “real-world” application? What are the best practices for using this syntax?
Nested functions are a non-standard extension, implemented by GCC (and maybe others that I don’t know about). Seeing as it does not follow a standard, best practices probably include not using it in code you intend to be portable.
If your ultimate goal is to have “private” functions in C, then you are better off using separate files and making the “private” functions static so that they won’t be linked to other object files.