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
0
votes
1 answer

Angular dead code of conditional provider in production bundle

I need to replace a service with a mock service depending on an environment variable. To do this, I used the ?-operator in the provider area within my module like this: @NgModule({ imports: [ ... ], providers: [ ... environment.e2e…
F. Scholz
  • 45
  • 4
0
votes
1 answer

How to ignore files from being compiled if they are not bein used

I am building a TypeScript project where I have want to generate output file depending on some conditions (For the actual project it depends on env). I am giving a simplified code example below. I am using webpack to build the…
0
votes
0 answers

Is it possible, in JavaScript, to eliminate code branches by tracking their arguments?

I tried to find some tool that would do this, but prepack is not quite doing what I want and other tools are failing at this particular example. I think it's quite common in programming to use functions in which some of the arguments are constants…
Artur
  • 3
  • 2
0
votes
1 answer

How can I find dead code in multiple solutions?(c#)

The source consists of more than 10 solutions. One of these solutions has dozens of public methods that the other solutions can refer to. How can I find dead codes that are not referenced in each solution among the public methods? I heard that…
daish
  • 1
0
votes
6 answers

Unreachable statement in java while loop

While loking up "dead code" thread here dead code warning in eclipse I tried the following simple java code: public class Test2 { public static void main(String[] args) { int x = 0; while(false) { …
Ayusman
  • 8,509
  • 21
  • 79
  • 132
0
votes
1 answer

Is GCC keeping inlined version of function when linking with --gc-sections

I would like to detect unused functions in my code by using the combination of -ffunctions-sections compiler options, and the --gc-sections,--print-gc-sections However, it shows false positive. Here is a simple reproducer : mylib.c : int plusone(int…
shodanex
  • 14,975
  • 11
  • 57
  • 91
0
votes
0 answers

Finding dead code in production environment using code coverage tool

I'm working on a huge monolith Java application with over 15000 lines of code that has been developed for quite a while now. My task is to find dead code (code that is never used) in the application. My idea was to approach this with JaCoCo code…
ripsta
  • 1
  • 2
0
votes
2 answers

What is AST,CFG,CLANG, how can we use it in deadcode removal algorithm?

I am about to write a dead-code removal algorithm using C language for an online event with our team. The requirements are..... To read a C program source file,Which has many forms of dead-codes. And our output should be a file, Which is free from…
Muthu Ganapathy Nathan
  • 3,199
  • 16
  • 47
  • 77
0
votes
2 answers

Dead code warning when setting color dynamically

I'm trying to make buttons that turn grey after having been pressed. I read up on how to do this. The best way I could find is to set the material color with a ternary operator and then change the condition for that in a setState(() {}) block: …
Anteino
  • 1,044
  • 7
  • 28
0
votes
0 answers

understanding compiler optimization in gcc

Does gcc understand or lookahead branches and perform optimization. I wrote a code like this for (int i = 10;i < 20;i++) { long long sum = 1; for (int j = 0;j < 10000;j++) { sum += pow(i,3); } if (i == 15) { …
0
votes
1 answer

How to annotate a program to detect dead-code with z3-solver?

Intro Given a simple function written in C++ as below: int func(int x, int y) { if (x < 3) { y = 4; if (x < 4) { y = y + 2; } else { x = x + 4; } } else …
Farzan
  • 745
  • 10
  • 25
0
votes
3 answers

Dead code with Xcode anaylser

i wanted to analyse my projet, and xcode analyser find some Dead Code in my rootcontroller Xcode tell me that : Dead code The left operand to '+' is always 0 -> Variable 'i' initialized to 0 -> The left operand to '+' is always 0 Can someone…
a3116b
  • 337
  • 1
  • 5
  • 13
0
votes
1 answer

Java. Handle dead code (by application logic) in catch block

I have the following piece of code. Path path = Paths.get(file.getAbsolutePath()); ByteArrayResource resource = null; try { resource = new ByteArrayResource(Files.readAllBytes(path)); } catch (IOException e) { // DEAD CODE. // file…
datarell
  • 3
  • 2
0
votes
0 answers

GCC links symbols for an unreachable switch-case statement

I'm writing a code with C that uses the factory pattern to initialize objects for specific interfaces. It simply assigns functions to related pointers according to the type. My interface and main application look like this: typedef enum { …
kurtfu
  • 498
  • 2
  • 4
  • 15
0
votes
2 answers

the code in my else statement is dead and I don't believe it is true (java)?

I am working with an organized BST in my java code. This function/method is supposed to search the tree for a node with a specific value and let the user know whether or not it exists. void search(int item, Node root, int r, int c) { …