suppose a function f1 is running and there on getting a condition true, the program should jump to the starting of main function,then how will I do this.remember main called f2() and f2() called f1().
f1()
{
code...
if( condition 1 is true)
{
jump to starting of main and never return here
}
code....
}
f2()
{
code....
f1();
code...
}
main()
{
code...
f2();
code;
}
@ResidentBiscuit : I'm design server.In that if the error occurred the program unbound the socket cleans WSA data and then returns to beginning of main where a function to bind the socket is called.
@moorecm: Thanx for the cooperation but I resolved the problem by using setjmp.h. I read about it right now over here
I can think of some hacks to make it work, but nothing anyone would call "elegant", but it looks as if you found a solution now. Sorry we couldn't be more help!
> suppose a function f1 is running and there on getting a condition true, (A)
> the program should jump to the starting of main function (B)
In the execution path between A and B, if and only if
a. there are no local objects (including anonymous temporaries) which have non-trivial destructors
b. there are no try/catch constructs
c. no exceptions would be thrown
I don't think I'd describe "put everything in main" as elegant.
Your inference is not the same as the statement's intent. Restructuring is necessary, as the requirement to "magically jump" in this context is evidence that the program is, well, already broken.
Correctness, simplicity, and clarity come FIRST. These principles are, by definition, elegant.