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

interfaces without implementation in Java

is there a quick way to find (may be by using intellij or maven etc) all the interfaces (java) without any implementation. I need to do above as we did some clean up of code where we removed a number of classes (and corresponding interfaces) which…
2
votes
8 answers

How do you define 'unwanted code'?

How would you define "unwanted code"? Edit: IMHO, Any code member with 0 active calling members (checked recursively) is unwanted code. (functions, methods, properties, variables are members)
NileshChauhan
  • 5,469
  • 2
  • 29
  • 43
2
votes
1 answer

Remove all unused code based off of a single Main method

Do you know any way to find (un)used code from the perspective of a specific main method (or what IntelliJ calls an entry point)? The background is that we have a big java project in which we have custom code for several clients. Sometimes we give…
2
votes
1 answer

GCC is neither sinking assignements nor eliminating partial dead codes

I am trying to see whether or not the GCC applies partial dead code elimination optimization. Partial dead code elimination can be considered as the result of the two opt passes: assignment sinking + dead code elimination. For example x = 3; …
dwijesh522
  • 29
  • 4
2
votes
2 answers

"Dead code" in Xilinx

I have some VHDL code I'm writing for a class. However, the synthesis tool identifies cell3, cell2, and cell1 as "dead" code and it won't synthesize it. I really have no idea what's going on to cause cell 3,2,1 to be removed in synthesis; I've…
Paul Nathan
  • 39,638
  • 28
  • 112
  • 212
2
votes
1 answer

"VFY: dead code" when attempting to use getBytes(Charset)

Everything was working fine in my app. Then, I did a small refactoring and a key component stopped working. When I looked at the LogCat output, this is what I found: WARN/dalvikvm(488): VFY: unable to resolve virtual method 10830:…
dmon
  • 30,048
  • 8
  • 87
  • 96
2
votes
2 answers

Identify Unlinked Pages - ColdFusion Builder

We have a large number of legacy pages in our application's code repository which are not linked to other pages. Is there a way in ColdFusion Builder to see which pages are not linked so they can be deleted? (Builder is derivative of Eclipse, so the…
2
votes
1 answer

Is it possible to create a "weak export" in TypeScript

One unfortunate thing about testing modular code is that sometimes you have to export things just to test them. This pollutes your code, and it also makes nice features like "unused variable" flags on the compiler or linter less valuable - if you…
javajosh
  • 510
  • 5
  • 12
2
votes
2 answers

Why am I getting dead code warning here in java?

I'm getting dead code warning in eclipse from the if(line == null) statement to the r.close() statement. BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); int counter = 0; while(true) { String…
Gergő Gutyina
  • 129
  • 1
  • 12
2
votes
1 answer

Ember and Dead Code elimination / Tree shaking

I have an app that has a dependency on a few bigger libraries and ember addons. From those dependencies, I use a very small subset of functions and components so I was surprised that in the final output is everything. I would like to stripp off…
ondrej
  • 967
  • 7
  • 26
2
votes
1 answer

Nodejs API code coverage based on actual production traffic

I'm working on a quite large nodejs code base which have been refactored and migrated from legacy to new service version several times and I highly suspect that some code is not used any more. This dead code is still well tested, but I would like to…
Pierre
  • 45
  • 7
2
votes
1 answer

Understanding avoiding Dead-code eliminations consequnces

I'm reading JMH samples and now I'm at the section about safe-looping. Here is an example: @Benchmark public void measureRight_2() { for (int x : xs) { sink(work(x)); } } @CompilerControl(CompilerControl.Mode.DONT_INLINE) public…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
2
votes
1 answer

Dead code removal of extern'd global

I'm wondering if the compiler/linker will remove global variables that have been extern'd in a public header? For example: // public.h struct func_ptrs { void (*foo)(void); void (*bar)(int); }; extern const struct func_ptrs…
MarkP
  • 4,168
  • 10
  • 43
  • 84
2
votes
1 answer

Dead code removal if implementation is overwritten

I'm in the process of writing a library that provides a sha256 implementation. The library will be given to vendors that may want to provide their own sha256 functions that are optimized for their platform. So, the API of this library allows the…
MarkP
  • 4,168
  • 10
  • 43
  • 84
2
votes
1 answer

Dead code elimination in switch statement

Imagine that the following function exists in a static library (*.a, *.lib): int func_foo(int i) { switch (i) { case 1: return foo_bar(); case 2: return foo_baz(); case 3: return foo_bat(); default: …
MarkP
  • 4,168
  • 10
  • 43
  • 84