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

How do I use Xdebug to help me find dead code?

When I run my PHPUnit tests, Xdebug generates a nice code coverage report which shows me exactly how many times each line of code was executed in each of my PHP files. I want to get the same report for my web site under, say, a week of normal use,…
Brian Kendig
  • 2,452
  • 2
  • 26
  • 36
1
vote
3 answers

Dead code java eclipse

I am trying to check if the word given by the user already exists in the text file or a substring of it already exists. Here's my code: String ans = null; Scanner scanner = null; do { System.out.print("Please enter a new word: "); String…
Charbel
  • 177
  • 1
  • 5
  • 14
1
vote
3 answers

Dead code in double for loop

I recently started coding in Java, and I have met this dead code problem. I have been looking at other questions (and answers) at Stack Overflow but I haven't found a solution yet. Hopefully you can help. The problem occurs at t++ public static…
roarknuppel
  • 269
  • 1
  • 2
  • 8
1
vote
3 answers

static variable initialisation code never gets called

I've got an application that's using a static library I made. One .cpp file in the library has a static variable declaration, whose ctor calls a function on a singleton that does something- e.g. adds a string. Now when I use that library from the…
B..
  • 13
  • 2
1
vote
2 answers

How to detect unreferenced C/C++ code on Visual Studio 2005?

I've being using Visual Studio 2005 for several years, and usually projects grow and grow, but now I have a project that is going down size, I'm taking away a big chunk of it (almost half of it)... I expected that by deleting the entry point…
1
vote
1 answer

Strange behaviour of gcc, well its ld (linker) options to remove unused functions

I am trying to remove unused functions (having no calls made to them) in my code which is built on x86 / Linux using gcc/g++. I use below options as I read from the gcc manual: CCFLAGS = -ffunction-sections -fdata-sections…
goldenmean
  • 18,376
  • 54
  • 154
  • 211
1
vote
1 answer

How to make an object file that cannot be dead_stripped?

What is the easiest way to produce a Mach-O object file that does not have the SUBSECTIONS_VIA_SYMBOLS flag set, such that the linker (with -dead_strip) will not later try to cut the text section into pieces and guess which pieces are used? I can…
hmakholm left over Monica
  • 23,074
  • 3
  • 51
  • 73
1
vote
1 answer

Javascript : Event listener defined inside function of object literal making the code dead

I have created the following code http://jsfiddle.net/N65yS/41/ .. My problem is this.. When I click on the 'draw' button ,for the first time it is working..Succeding clicks on the button is not calling the listener. Why is this happening... Is…
Jinu Joseph Daniel
  • 5,864
  • 15
  • 60
  • 90
0
votes
1 answer

dead code android setMultiChoiceItems

i use setMultiChoiceItems for a list in a dialog. when click on ok the code is .setPositiveButton(R.string.alert_remove, new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int which){ String[] res = null; for(int…
Nik Tsekouras
  • 289
  • 2
  • 15
0
votes
1 answer

How to tailor a jQuery based javascript library to my own needs?

I use a library which provides lots and lots of utility functions. It's based on jQuery, so I have to include jQuery too. Both of these libraries are huge in size but I only use a single functionality in a single function only once. I've gathered…
Murat Derya Özen
  • 2,154
  • 8
  • 31
  • 44
0
votes
1 answer

Rust dead code analysis for code exposed only to the binary in the same lib crate

Across our database, many crates expose both lib.rs, and main.rs, effectively forcing the binary to be an "external" user of its own crate. The crate usually exposes a configuration and a set of public functions that consume the configuration in…
sukhmel
  • 1,402
  • 16
  • 29
0
votes
3 answers

Java dead code warning + no rectangle forming?

I am unsure as to why I'm getting a dead code warning for my for loops, and I also don't know why only 1 of the symbols is printed, rather than the desired rectangle. public static String rectangle(int row, int col, char thing) { for (int i = 0;…
Anofex
  • 11
0
votes
0 answers

dead code removal doesn't work for assembly code?

Apparently gcc -Wl,--gc-sections doesn't remove unused functions written in assembly code, even if the .S file is compiled with -ffunction-sections. objdump -x doesn't show the code in its own ELF section. I could manually add a .section in front of…
Yale Zhang
  • 1,447
  • 12
  • 30
0
votes
1 answer

dead_code warning in Rust when Debug printing a struct

I am very new to Rust and I am wondering about the warning produced by the following code before it runs. I am running version: rustc 1.67.0 (fc594f156 2023-01-24) from the stable channel. 1 #[derive(Debug)] 2 //#[allow(dead_code)] 3 struct…
0
votes
4 answers

Dead code warning

while(true){ try { if(Calendar.DATE == X){ startTask(); } long delay = timeUntilNextCheck(); Thread.sleep(delay); } catch (Throwable t) { } } I have a program that requires a…
user918076