unreachable-code

How to hint to GCC that a line should be unreachable at compile time?

余生长醉 提交于 2020-12-25 01:55:10
问题 It's common for compilers to provide a switch to warn when code is unreachable. I've also seen macros for some libraries, that provide assertions for unreachable code. Is there a hint, such as through a pragma, or builtin that I can pass to GCC (or any other compilers for that matter), that will warn or error during compilation if it's determined that a line expected to be unreachable can actually be reached? Here's an example: if (!conf->devpath) { conf->devpath = arg; return 0; } // pass

How to hint to GCC that a line should be unreachable at compile time?

烂漫一生 提交于 2020-12-25 01:52:29
问题 It's common for compilers to provide a switch to warn when code is unreachable. I've also seen macros for some libraries, that provide assertions for unreachable code. Is there a hint, such as through a pragma, or builtin that I can pass to GCC (or any other compilers for that matter), that will warn or error during compilation if it's determined that a line expected to be unreachable can actually be reached? Here's an example: if (!conf->devpath) { conf->devpath = arg; return 0; } // pass

How to hint to GCC that a line should be unreachable at compile time?

╄→尐↘猪︶ㄣ 提交于 2020-12-25 01:50:49
问题 It's common for compilers to provide a switch to warn when code is unreachable. I've also seen macros for some libraries, that provide assertions for unreachable code. Is there a hint, such as through a pragma, or builtin that I can pass to GCC (or any other compilers for that matter), that will warn or error during compilation if it's determined that a line expected to be unreachable can actually be reached? Here's an example: if (!conf->devpath) { conf->devpath = arg; return 0; } // pass

Unreachable return statement still throws error

橙三吉。 提交于 2019-12-25 02:28:23
问题 I have this very simple code snippet: static String getInput() throws IOException{ if(in.ready()){ return in.readLine().trim(); } System.err.println("Please provide more input in order to execute the program."); System.exit(0); return ""; } By what I think I know, there is no possible way that the JVM will execute the return statement at the end of the code. But if I comment this line out, java will complain about a missing return statement. Why doesn't the JVM recognize that a System.exit(0)

Java: How to @SuppressWarnings unreachable code?

匆匆过客 提交于 2019-12-19 15:26:32
问题 Sometimes when you are debugging, you have unreachable code fragment. Is there anyway to suppress the warning? 回答1: The only way to do this on any compiler is @SuppressWarnings("all") . If you're using Eclipse, try @SuppressWarnings("unused") . 回答2: Java has (primitive) support for debugging like this in that simple if on boolean constants will not generate such warnings (and, indeed when the evaluation is false the compiler will remove the entire conditioned block). So you can do: if(false)

Java: How to @SuppressWarnings unreachable code?

陌路散爱 提交于 2019-12-19 15:26:05
问题 Sometimes when you are debugging, you have unreachable code fragment. Is there anyway to suppress the warning? 回答1: The only way to do this on any compiler is @SuppressWarnings("all") . If you're using Eclipse, try @SuppressWarnings("unused") . 回答2: Java has (primitive) support for debugging like this in that simple if on boolean constants will not generate such warnings (and, indeed when the evaluation is false the compiler will remove the entire conditioned block). So you can do: if(false)

Unreachable code, but reachable with an exception

扶醉桌前 提交于 2019-12-18 11:14:03
问题 This code is part of an application that reads from and writes to an ODBC connected database. It creates a record in the database and then checks if a record has been successfully created, then returning true . My understanding of control flow is as follows: command.ExecuteNonQuery() is documented to throw an Invalid​Operation​Exception when "a method call is invalid for the object's current state". Therefore, if that would happen, execution of the try block would stop, the finally block

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

心不动则不痛 提交于 2019-12-17 03:42:12
问题 I tried the following in Eclipse: if (false) {} : warning 'dead code' while (false) {} : compilation error 'unreachable code' I was wondering whether there is a real 'reason' for this difference. I already found this... Unreachable code compiler error ...but why not allow while (false) for the same debugging purpose? 回答1: 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

Why is the code in my foreach unreachable? (Exact copy of working code thats been Unit tested)

这一生的挚爱 提交于 2019-12-10 15:35:21
问题 The code below is an exact copy of code that's working perfectly. The difference is that this code is being placed in a WCF Service Application Project whereas the working code is from a Windows Forms Application Project. The code in the foreach is unreachable which is strange because I've tested the code before and it works, returning the correct values public IEnumerable<Employee> GetStudentDetails(string username,string password) { var emp = agrDb.LoginAuthentication(username, password);/

Why unreachable code isn't an error in C++?

拥有回忆 提交于 2019-12-09 20:50:39
问题 unreachable code is compile time error in languages like Java. But why it is just warning in C++ & C? Consider following example: #include <iostream> int f() { int a=3; return a; int b=6; // oops it is unreachable code std::cout<<b; // program control never goes here } int main() { std::cout<<f()<<'\n'; } Shouldn't compiler throw an error in this program, because statements after return statements in function f() will never get executed? What is the reason for allowing unreachable code? 回答1: