unreachable code is compile time error in languages like Java. But why it is just warning in C++ & C? Consider following example:
#include <iostream>
int f()
{
int a=3;
return a;
int b=6; // oops it is unreachable code
std::cout<<b; // program control never goes here
}
int main()
{
std::cout<<f()<<'\n';
}
Shouldn't compiler throw an error in this program, because statements after return statements in function f() will never get executed? What is the reason for allowing unreachable code?
return
while working on the code in the function or the code calling the function. – Roumell