Can branches with undefined behavior be assumed unreachable and optimized as dead code?

Does the existence of such a statement in a given program mean that the whole program is undefined or that behavior only becomes undefined once control flow hits this statement? Neither. The first condition is too strong and the second is too weak. Object access are sometimes sequenced, but the standard describes the behavior of … Read more

if(false) vs. while(false): unreachable code vs. dead code

The JLS section on unreachable code explains the rationale. Essentially, Java normally shouldn’t use conditional compilation like C routinely does with #ifdef, but there are some situations (such as debugging, and in particular backward binary compatibility) where allowing the compiler to entirely strip out code is needed, and so the specific construct if(false) is permitted … Read more

Unreachable code ; i dont understand why it is unreachable

First, analyse your code, Have a look at block case 3: { System.out .println(“You head towards Moat Caillin. the journey is swift and you are greeted by the Lord of Moat Caillin”); System.out .println(“The Lord of Moat Caillin offers your his company for dinner. type in your desired option”); System.out.println(“1: accept the lords offer.”); System.out.println(“2: … Read more