|
|
|
|
|
by kazinator
2166 days ago
|
|
> In C a nested function can also jump into a parents goto label. It positively cannot, because, 1. There is no such thing as a nested function in ISO C. It's a GCC extension. 2. Let's try it the GCC extension: #include <stdio.h>
int main(void)
{
void foo()
{
goto out;
}
foo();
puts("skipped");
out:
return 0;
}
This does not compile: nestedgoto.c: In function ‘foo’:
nestedgoto.c:7:6: error: label ‘out’ used but not defined
goto out;
^~~~
Maybe you can use a computed label and pass it as an argument? #include <stdio.h>
int main(void)
{
void foo(void *target)
{
goto *target;
}
foo(&&out);
puts("skipped");
out:
return 0;
}
Well, that compiles now but: $ ./nestedgoto
*** stack smashing detected ***: <unknown> terminated
Aborted (core dumped)
In addition to Common Lisp: [8]> (tagbody
(funcall (lambda () (go out)))
(print 'skipped)
out
(print 'out))
OUT
NIL
another notable language which can do this is PL/I. To tie this a bit more to the topic, PL/I is incidentally where conditions come from, including the "condition" terminology. |
|