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
1
vote
3 answers

Dead code in eclipse when trying to find the sum of an array

I tried to find the sum of any array by using the for loop but the i++ part ended up being the deadcode unreachable. I don't understand why? public static int sum(int[] data) { int sum = 0; int i; for (i = 0; i <…
Steve
  • 35
  • 5
1
vote
1 answer

Why is rust complaining about an unused function when it is only used from tests?

When a function is only called from tests rust complains that it is never used. Why does this happen and how to fix this? Example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=52d8368dc5f30cf6e16184fcbdc372dc fn greet() { …
1
vote
1 answer

GCC deadcode elimination

Does GCC, or do compilers in general, remove variables which are operated on, yet do not at all affect the result of the code? For example, say main only contained int a = 0; int b = 0; for (int i = 0; i < 10; i++) { a += 10; b +=…
tmako
  • 349
  • 2
  • 9
1
vote
1 answer

Identifying if/else statements in R and extracting expressions from them

I would like to extract expr_a, expr_b, expr_c from the if/else block in the following function: test <- function() { result <- if (expr_a) expr_b else expr_c return(result) } for the…
adityar
  • 142
  • 5
1
vote
0 answers

How to stop dead code elimination for one particular statement in Angular 7

I am using bootstrap carousel for my angular 7 project. One of the statement for carousel animation is as below, which basically reflows the screen. $next[0].offsetWidth Now, when generating prod build, angular removes this line (during…
1
vote
1 answer

Clojurescript dead-code elimination apparently not working

I have a ClojureScript project with the following barebone frontend app (main being the entry point): (ns shadowman.app (:require ;; [cljs-http.client :as http] ;; [reagent.core :as r] )) (defn main "" [] (js/console.log "hi from…
1
vote
1 answer

selectively disable dead code elimination in a library

I have many cpp files, some of which have functions to self-subscribe to events. Unfortunately, most linkers will eliminate all symbols from compilation units if there is no apparent function call into them. Is there a way to force linking of these…
Tomas
  • 105
  • 7
1
vote
0 answers

Find dead code in large Javascript Application

I have a very large Nodejs application. There is a lot of unused dead code. I have been looking for a solution for this, but Im not able to find the proper tool. I see there are many tools to check dead pieces of code or unreachable code in the own…
Rashomon
  • 5,962
  • 4
  • 29
  • 67
1
vote
2 answers

How to find dead code in C language Project with gcc compiler

I need to find the dead code(functions not used) in my "C" language Project(having multiple C files) with gcc compiler. Please let me know the gcc options to find the dead code. Your help will be greatly appreciated.
siva
  • 31
  • 2
1
vote
1 answer

react CRA - exclude debug code from build

Is there any method to completely exclude some code from if statements in production mode?? I was trying to do something like that: import React from "react"; import Loadable from 'react-loadable'; function Loading() { return
; } let…
1
vote
0 answers

How to keep track of methods used in Java

Is there a way to keep track of methods from all files used by a particular module (all files that are used to complete the functionality of a module) without using existing tools. I would like to hear your thoughts on how to design a tool that…
Kael
  • 391
  • 1
  • 10
  • 21
1
vote
2 answers

A better way to mark a line, that will never be reached?

Assuming this code snippet: public synchronized void kill() { log.info("Killing {}...", this); Runtime.getRuntime().halt(HALT_STATUS_CODE); assert false; // Line should never reach this point! } Since the assert depends whether or…
KeyMaker00
  • 6,194
  • 2
  • 50
  • 49
1
vote
1 answer

Webpack doesn't respect 'module' field in package.json

I am trying to figure out tree-shaking in Webpack and I noticed that running -webpack -optimize-minimize on this Example1 is 11kB, while on Example2 it is 7kB. The library Rambda has a field module in its package.json. As far as I can see Webpack…
Dejan Toteff
  • 2,075
  • 3
  • 21
  • 30
1
vote
0 answers

How to run inspection for finding all unused classes?

When a new class has just been created, IntelliJ Idea marks it as unused and suggests to delete it. But where does this inspection actually live? I tried to run inspection by name and found "Unused Declaration" which has a dozen (in my opinion)…
Cherry
  • 31,309
  • 66
  • 224
  • 364
1
vote
0 answers

Dead code analysis in VisualStudio 2013 Pro

I need to remove unused variables and functions(Deadcode) in a c code. Can I use VisualStudio 2013 Pro code analysis to find unused c variables? Because in the rule set, Microsoft.Performance rules are not available for unmanaged code. is there any…