In article <wi**************************@malibu.unice.fr>,
Jean-Guillaume Pyraksos <wi****@hotmail.comwrote:
>Is a label something like a pointer i can store in a variable ?
As others have pointed out, only when using an extension like the
one that gcc provides.
>void foo(void *p)
{
printf("foo\n");
goto *p;
}
int main()
{
foo(&&L1); // ???????? Explain...
printf("bar\n"); // should not be executed ?
L1:
printf("quit\n");
return 0;
}
>Can somebody elaborate on this code i found on the net ?...
Again, as others have pointed out, this code is using the gcc
extension wrongly. You should only use it for jumps where a
normal jump to the location would be legal.
>gcc compiles it but the result is strange (MacIntel Leopard, gcc 4.0.0)
$ gcc prog.c -o prog
$ ./prog
foo
r is not present to run this program
bar
quit
My guess would be that the goto is "working", but because the function
foo is still active the format string "quit" is not in the right place
relative to the stack pointer, and instead it gets the end of some
other string (you can find what it probably is by googling for "is not
present to run this program"). It then executes main's return, but
because foo's stack frame is still there it returns to main, and
continues executing normally.
-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.