answersLogoWhite

0


Best Answer

Unreachable code is code that can never execute. It usually happens when you have a logic error in your code, such as when an if condition always evaluates true (or false). For example:

int foo(int& x)

{

if( &x == NULL ) // always evaluates false...

{

// Unreachable code:

std::err<<"int foo(int&) : argument int& is a NULL reference"<<std::endl;

return(-1);

}

return(0);

}

In the above example, the entire if() statement is redundant because the argument, x, is a reference. In C++, references can never be NULL, so the if statement can never evaluate true. Furthermore, in this particular example, the entire function can be said to be redundant (but not unreachable), simply because it serves no purpose. It will always return zero.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is unreachable code in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How in C or C plus plus to static assert that a place in code be unreachable?

The only way to assert unreachable code is to place the assertion, assert(0), within the suspected unreachable code itself.However, just because the assertion never triggers it does not follow that the code is unreachable -- only that the condition(s) required to reach that code segment have not thus far arisen. How certain can you be that the condition will never arise?Unreachable code can sometimes be detected at compile time, depending on the compiler. Simple errors such as placing a return statement before unreachable code can normally be detected this way. However, logic errors may not always be as obvious.For instance,if( !condition )// do something.else if( condition )// do something else.elseassert( false ); // unreachable...In general, if there is no logical proof to say a code segment is unreachable, it's best to leave the segment in place. An assert( false ) will alert you when the segment is hit, but even if it is never hit, you cannot be certain it will never be hit without a logical proof. If the unreachable code is trivial then it is usually not worth the effort to prove it is unreachable. If it is non-trivial, the only issue is how you test it in the event it is actually reachable. In that case you must force the conditions that would make it reachable.


What is the Visual C plus plus 2008 Express Serial Code?

The Express edition of C++ does not require a serial code. It is free.


Where can you get the mseb bill generation project in c plus plus?

No such code exists for MSEB Bill Generation in C++.


What colour code in c plus plus?

0-black.2-green


What does generic programming in c plus plus means?

Generic programming means that the code is generic enough that it compile on any C++ implementation. That is, it has no platform-specific code.

Related questions

How in C or C plus plus to static assert that a place in code be unreachable?

The only way to assert unreachable code is to place the assertion, assert(0), within the suspected unreachable code itself.However, just because the assertion never triggers it does not follow that the code is unreachable -- only that the condition(s) required to reach that code segment have not thus far arisen. How certain can you be that the condition will never arise?Unreachable code can sometimes be detected at compile time, depending on the compiler. Simple errors such as placing a return statement before unreachable code can normally be detected this way. However, logic errors may not always be as obvious.For instance,if( !condition )// do something.else if( condition )// do something else.elseassert( false ); // unreachable...In general, if there is no logical proof to say a code segment is unreachable, it's best to leave the segment in place. An assert( false ) will alert you when the segment is hit, but even if it is never hit, you cannot be certain it will never be hit without a logical proof. If the unreachable code is trivial then it is usually not worth the effort to prove it is unreachable. If it is non-trivial, the only issue is how you test it in the event it is actually reachable. In that case you must force the conditions that would make it reachable.


Is C plus plus preprocessor software?

Sometimes, it is. Some implementations compile C++ code into C code, and then compile the C code.


What is the mean c plus plus in machine code?

It is used to distinguish between the C or C++


How do you Open a text file as C plus plus source code?

All C++ source code is is a text file with the .cpp extension. So if you save your code as *****.cpp then it is automatically C++ source code.


What is the Visual C plus plus 2008 Express Serial Code?

The Express edition of C++ does not require a serial code. It is free.


C plus plus code for payroll processing?

yihuy


What is the code to include a library in c plus plus?

#include &lt;libraryname&gt;


What are the steps in c plus plus?

Code, compile, link, run.


What is the differentiate of turbo c from turbo c plus plus?

Turbo C compiles c source. turbo c++ compiles c++ source code.


How C plus plus is better than C?

C++ is a language code for computer and lapatops which is used in programming but C is a grade so they are different.


Where do you get c plus plus software?

A good open source IDE for C++ would be Code::Blocks or Notepad++.


Where can you get the mseb bill generation project in c plus plus?

No such code exists for MSEB Bill Generation in C++.