Is it the only case a reachable goto pointing to an unreachable label?
Asked Answered
R

1

6

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;
Regan answered 4/3, 2013 at 23:28 Comment(2)
A question without any vote, answer, or even a comment for four hours is really weird ..Regan
The C# specification would consider your goto here; reachable because reachability only considers values of constants. 1/d is not a constant.Doer
D
12

The finally-blocked goto trick is in fact the only way to get a reachable goto that targets an unreachable label.

Doer answered 5/3, 2013 at 6:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.