Questions tagged [dead-code]

Dead code is code in the source code of a program which is executed but whose result is never used or a code that can never be reached or used.

Dead code is code in the source code of a program which is executed but whose result is never used or a code that can never be reached or used.

Dead code is waste of computing power and might result of unexpected behavior to the program.

Examples:

int foo (int a, int b)
{
    int c = a + b;  // dead code - executes and result never used 
    return a - b;
}

void foo ()
{
     bool a = true;
     if (!a)
     {
         // dead code - never called
     }
}
238 questions
5
votes
3 answers

In Eclipse, how do you find methods that you have defined but not used/called anywhere in the app?

I am concerned that some of the classes in my app have methods that are defined but not called anywhere in the app. In Eclipse is there a way to find these methods?
Daniel K.
  • 105
  • 2
  • 5
5
votes
3 answers

Where does the dead code come from?

I've got a problem, I'm getting a "Dead Code" warning in Eclipse and I really don't know why. The code is from my Connect Four project, to be more precise it's from the Class that checks if somebody has won. This method checks all the horizontal…
Lunaetic
  • 229
  • 2
  • 9
5
votes
3 answers

Why do I get a "dead code" warning in this Java code?

Would someone please tell me why i am getting a dead code warning in the else branch of if (projectId != null) ? If i got this right, the interpreter thinks projectId can never be null - is that right? In my opinion this is not possible... Integer…
nidhoeggr09
  • 153
  • 6
5
votes
5 answers

Why does Eclipse complain about dead code?

Eclipse keep stating that the last elseif and the else is dead code but I don't get it. if (img0 != null && img1 != null) { code; } else if (img0 != null) { code; } else if (img1 != null) { code; } else { code; } I reason like…
evading
  • 3,032
  • 6
  • 37
  • 57
5
votes
2 answers

dead code warning in the i++ part in the for loop

This code keeps giving me a dead code warning on the i++ in the for loop and it is not incrementing the i for some reason! import java.util.Scanner; public class HideThatNumber { /** * @param args */ public static void…
user1712638
  • 201
  • 2
  • 8
  • 22
4
votes
2 answers

Are unused classes compiled by Xcode when building an app?

If something is not used in C++, it's not compiled at all. Is the same true for iPhone? If I compile a program and there are unused classes or other stuff, will it be compiled or ignored?
anijam
  • 351
  • 1
  • 4
  • 13
4
votes
1 answer

Remove unused variables in Python source code

The Question Is there a straightforward algorithm for figuring out if a variable is "used" within a given scope? In a Python AST, I want to remove all assignments to variables that are not otherwise used anywhere, within a given…
shadowtalker
  • 12,529
  • 3
  • 53
  • 96
4
votes
1 answer

Is v8 capable of dead code elimination, based on the value of the `const`?

Question for the v8 developers/experts. Is it correct to assume, that v8 will completely eliminate the dead code, structured like this: module1.js export const DEBUG = false module2.js import { DEBUG } from './module1.js' if (DEBUG) { // dead…
4
votes
3 answers

Performance of function call in Common Lisp SBCL

I'm new to Common Lisp and ran into a performance thing that just struck me as weird. I'm checking if a number is divisible by 10 using rem in a loop. If I move the check into a function, it runs 5x slower. What would cause that? I'm running sbcl…
Rich
  • 423
  • 4
  • 11
4
votes
1 answer

How to identify unused code & files in QML

Need to identify dead code and unused files in the codebase for QML & JS files. Are there any tools for Qt/C++?
Ravisha
  • 3,261
  • 9
  • 39
  • 66
4
votes
1 answer

Code after return statement without warning

We just found an issue in our code base, where a statement is after a return statement. e.g. std::string MyClass::addElement(Type1 &item, const std::string ¶m2) { if (param2.empty()) { // logging return ""; } …
Simon
  • 1,616
  • 2
  • 17
  • 39
4
votes
2 answers

Can inlining and dead code removal optimizations prevent template instantiations?

Given the following example code struct S; template class C { public: void f(bool b) { if (b) g(); } void g() { S{}; } }; int main() { C{}.f(false); } GCC correctly reports the…
Torben L.
  • 191
  • 1
  • 6
4
votes
3 answers

How to disable dead code elimination in the Java compiler?

This may seem a strange question... Why would anyone want to disable such a thing? But I know what I'm doing (and why I want/need to do this) and I really want to disable dead code elimination. Is it possible somehow? I use Eclipse by the way, if…
rfgamaral
  • 16,546
  • 57
  • 163
  • 275
4
votes
1 answer

gcc dead-code elimination with function pointers

I have a primitive understanding of how the linker does dead-code elimination of unused functions and data segments. If you use the proper compiler and linker flags it puts each function and data member into it's own section, then when the linker…
NickHalden
  • 1,469
  • 2
  • 20
  • 31
4
votes
3 answers

Obvious false condition in else if, not giving dead code for body inside

Going through some old code written by one of my teammate, I found this really strange code: if (...) { // some code } else if (this == null) { System.out.println("I expected this to be dead code!"); } Strange isn't it. AFAIK, this == null…
Rohit Jain
  • 209,639
  • 45
  • 409
  • 525