开发者

Can i point to a specific location in a function? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audi开发者_如何学Goence of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

Say i have this main int

int main();
{
 cout << " Hello! ";

 function1();

 cout << " BYE!";
}

Is there a way to make it so once im done with the function1 to make it just point to the top of 'cout << " BYE!";' so i dont have to go through Hello again? Basically i want to just point the end of function1 to the top of Bye. is this possible without ifs and all that?


This code already does that. Try running it!

(You will have to get rid of the semicolon after main())


when ever a function is completely executed. The c++ pointer tries to execute the statement which comes after the function. However if you want to point to some specific location you can use the statement

Goto to go to a specific label let us say abc:

int main();
{
 cout << " Hello! ";

 function1();
Goto label
...
....
...

label :
 cout << " BYE!";
}

however i dont recommend this.


so i dont have to go through Hello again

What you say makes no sense. It won't go back to Hello again, why do you think it would? That is not how things work.


I assume when you say you want to point to a specific location, you mean you want a first-class value that you can pass, store, etc, like a function pointer.

If that's the case, you might be interested in continuations, which provide this kind of behavior.

It's generally not possible to construct this functionality in a language that does not already have it; you need help from the environment. For C/C++, you might use System V contexts. I'm peering around for a library to abstract this away further for you, but nothing's jumping out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜