Nested functions — to be useful — you need a stack frame of the containing function as a context. Look at this:
class Foo() { void Tripulate() { int i=0; void Dip() {
What values should Dip () access have?
Not? you simply duplicated the functionality of (anonymous) namespaces, more or less.
Only for i, because it's the only one defined before the function?
Just for me and x, because they are in scope like Dip() ? Should the compiler make sure that the constructor x already running, or is this your job?
What about z?
If Dip accesses both the local tripulate values and the stack frame, so the internal prototype will be
void Dip(Foo * this, __auto_struct_Dip * stackContext) {
You basically replicated the functionality of structures / classes and member functions, but on two incompatible and non-exchangeable paths. This is a big challenge for dubious gain.
I wanted local functions several times, simply because it would better indicate the area in which it is needed. But with all the questions ... There are more useful things to put more complexity into C ++.
source share