Inspired from question
And before I ask this question, I've read:
The challenge in the question is
write a program which has a reachable goto statement but the corresponding labelled statement is unreachable - Eric Lippert
and one feasible answer is like
// the 3 lines are not important but declare variable for afterwards use
var whateverException=new Exception("whatever exception");
var whateverAction=default(Action);
whateverAction=() => whateverAction();
try {
goto whateverLabel; // (1) the goto is reachable
}
finally {
throw whateverException; // (3) because finally hijacks
}
whateverLabel: // (2) but the label is not really reached
whateverAction();
I'm wondering that in a single thread program, is it the only case a reachable goto pointing to an unreachable label? And is following code also considered a feasible answer of that?
here:
int d=0, n=1/d;
goto here;
goto here;
reachable because reachability only considers values of constants.1/d
is not a constant. – Doer