tags:

views:

105

answers:

2

hello.

Disclaimer, I not do anything in particular with regards this question, just curious.

Is it possible to take address of instruction or block in C? in essence, is there jump equivalent in C?

for example:

void function() {
    int k;
    { // is a possible to go to this address from arbitrary point in code?
      int i, j;
      k += j+i;
    }
}

thank you

+3  A: 

Yes, use goto:

void function() {
    int k;
    { // is a possible to go to this address from arbitrary point in code?
myLabel:
      int i, j;
      k += j+i;
    }

// stuff

    goto myLabel;
}
Jim Buck
but go to is scoped? Or is it not?
aaa
Goto isn't taking the address. Perhaps you were thinking of labels as values, a GCC extension? http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
Yann Ramin
"arbitrary point in code" - I didn't realize you meant from literally *anywhere* in your program. Yeah, goto is just for within the function. For anyplace in code, yeah, setjmp/longjump is your man.
Jim Buck
+3  A: 

I think the closest you can come using standard techniques is setjmp and longjump. They won't get you access to the actual address though, because the jmp_buf object is opaque.

Matti Virkkunen
cool. I did not know about this. thanks
aaa