Originally Posted by
Brian_Teir
what's confusing me is that if I have code after return function then the PC will neglect all the code rows that're found after return function, so how the PC neglect them if they are instructions in my program?
Because that's the way it is. It is like asking why the code in the else branch of an if statement is not executed when the condition is true. It is just how it was designed to be. If you write garbage, you get garbage.
Originally Posted by
Brian_Teir
so what's found after return 0 is neglected , so how the PC is neglect them although there're instruction-code- in the program itself? really weird, so /*code2 does something else*/ is trash.
It looks like /*code2 does something else*/ is unreachable, i.e., you might as well delete that piece of code because it is useless, and the compiler could treat it as if it didn't exist, and would likely warn you about it.
In other cases, it may depend on the flow of control, e.g.,
Code:
if (condition())
{
return;
}
foo();
So what we have here is an early return if condition() evaluates to true. If it doesn't, the flow of control goes on to foo().
Originally Posted by
Brian_Teir
what does that mean how the PC neglects them although they are code found in the program which means they are instructions that must be executed? thanks.
Actually, because they are unreachable, they are instructions that must not be executed. As I said, garbage in, garbage out. Program uselessly, get a useless program. Write code that is unreachable, get code that is unreachable junk.