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

proguard dead code analysis gives false positive for private field

Given the following class package com.example; public class ProguardConstantFieldUsageDemo { private static final String CONSTANT_FIELD = "I'm not dead!"; public String publicMethodUsingConstant() { return CONSTANT_FIELD + "I…
Ville Oikarinen
  • 400
  • 1
  • 11
0
votes
0 answers

Build with webpack when dead code references a module that's not present fails - is this unavoidable/expected behavior?

I'm sharing some code between environments and in one environment a dependency isn't available - but that code isn't imported into the project and the module uses sideEffects: false - I'd think I should be able to build the project, but if I'm…
Slbox
  • 10,957
  • 15
  • 54
  • 106
0
votes
0 answers

Is it dangerous to have test or unfinished files on a live site?

I am doing an rundown/audit/exploration on a website, and I have found several pages on the live version of the sites domain that are not actually in use, such as example-page2.php or registration-test.php. They do have their counterparts being the…
Meitie
  • 75
  • 1
  • 8
0
votes
1 answer

Flutter Dead code Listview while implementing ListTile

I would like to implement onTap in my ListView so I also need to implement return ListTile but I have a dead code on my ListTile snippet. I would like to know why and how to resolve it. There is my code : @override Widget build(BuildContext…
Itoun
  • 3,713
  • 5
  • 27
  • 47
0
votes
1 answer

Dead coding in C

Im analyzing the following code with different options of the compiler (O0 O1 O2 O3 Os). First of the iterations is out of the loop for "warming the cache". With O0 and O1 the time of ejecutions is different of 0.00 being higher as the input…
vps
  • 90
  • 10
0
votes
1 answer

Are empty loops with side effects in it's condition caught by dead code elimination?

Given the following code var cachedInt = new ArrayBlockingQueue(xxxxx); while(true){ while(cachedInt.offer(randomProvider.nextInt())); latch.await(); } Will the jvm eventually eliminate the while loop because it has no body or does…
Kilian
  • 1,540
  • 16
  • 28
0
votes
3 answers

Find out which code is never called in C++ project in Visual Studio 2012

I am using VS2012 and I would like to know which code in my project is never called. How can I do it? Here is the menu I tried out for the dead code analysis, but did not find it here.
0
votes
1 answer

Unexpected code after tree-shake

Given entry is the entry module: It just uses function1 from external1 module. I expected that external1.function2 and the whole external2 module would be eliminated. However, my output includes external2.function1. Just.. why? Here's a repo of…
Daniel Birowsky Popeski
  • 8,752
  • 12
  • 60
  • 125
0
votes
1 answer

How to eliminate dead webpack requires/imports?

I want to remove certain file require/imports depending on the environment (development/production) using Webpack (v2.5.1) and UglifyJsPlugin. Current situation export const IMAGES = Object.assign( { PROFILE: require('images/profile.png'), …
Renārs Vilnis
  • 1,160
  • 1
  • 10
  • 24
0
votes
1 answer

Why is this line in findNode method of BST being marked "dead code"?

I am attempting to implement a findNode method as part of a binary search tree in java. public Node findNode(int findkey){ Node tempNode5 = root; while(findkey != tempNode5.key){ if(tempNode5 != null){ // if the tempNode5 is not…
Zubin Mukerjee
  • 166
  • 2
  • 11
0
votes
2 answers

Can a variable become null by left or right shift operation in c / c++?

i have a code snippet in which i assign a value to a variable , var. In between the variable is acted upon left/right shift operations. Can such a variable ever become null. Note that null is mostly defined as #define null ((void*)0) If it can't…
user3552519
  • 401
  • 4
  • 11
0
votes
1 answer

Java dead code in different places

Sorry if I ask a stupid question, long time no practice with Java...... I wrote some code to simulate the Hash Table. Here is one function of my code: protected int find(K key){ int avail=-1; int i=hashValue(key); int j=i; do{ …
Prince Luo
  • 101
  • 1
  • 8
0
votes
1 answer

Xcode: would like to highlight soon-to-be-deprecated sections of source code

I'm searching for a method of highlighting sections of a source code file so that everyone on the team knows immediately that they are reading deprecated code. For example, I was hoping I would find something like this: #pragma clang diagnostic…
Keith Knauber
  • 752
  • 6
  • 13
0
votes
2 answers

What is the difference between Dead Code and Deactivated Code?

What is the difference between Dead code and Deactivated code as per DO178-b? Please provide some examples to highlight the difference.
Lax
  • 21
  • 1
  • 9
0
votes
2 answers

Write result to a volatile var to prevent dead-code elimination in tests

I'm going to measure performance of some code. For the purpose, I introduced the following method: def timed[T](body: => T) = { val start = System.currentTimeMillis blackHole = body val end = System.currentTimeMillis end - start } The…
Aliaxander
  • 2,547
  • 4
  • 20
  • 45