Can i point to a specific location in a function? [closed]
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.
精彩评论