On Sat, 2005-05-14 at 12:29 -0700, Richard Henderson wrote: > On Sat, May 14, 2005 at 11:59:28AM +0200, Øyvind Harboe wrote: > > void test(void (*t)(void)) > > { > > int i; > > for (i=0; i<10; i++) > > { > > t(); > ... > > int skip=0xdeadbeef; > > > > void do_goto (void) > > { > > goto l1; > > } > > > > test(do_goto); > ... > > l1: > > if (skip!=0xdeadbeef) > > } > > > > int main () > > { > > recursive (10, abort); > > abort (); > > } > > Well of course your program always aborts. Control never enters > the recursive part of recursive(). It flows straight through and > returns, which hits the abort in main.
Ah. So the goto acts like a longjmp in this context... Running test below produces $ gcc test.c -g -O1 $ ./a.out j=11 $ -- Øyvind Harboe http://www.zylin.com #include <stdio.h> int j; void test(void (*t)(void), int i) { j++; if (i>0) { test(t, i-1); } else { t(); /* never reached */ abort(); } j--; } void bar (void) { __label__ l1; void do_goto (void) { goto l1; } test(do_goto, 10); l1:; } int main () { bar(); printf("j=%d\n", j); return 0; }