dead code identification

Diego Novillo dnovillo@google.com
Wed Feb 13 17:03:00 GMT 2008


On 2/13/08 11:58 AM, Mark Hampton wrote:

> Could you explain the difference please.

Sure.

Unreachable code:


foo (int i)
{
    if (1)
      return i + 3;

    return i - 2;	<-- Unreachable code
}

Dead code:

foo (int i)
{
   int x;

   x = i + 1;		<-- Dead code
   x = 4;
   return x * 2;
}

They are similar in that neither has any effect on program output.

They are different in that unreachable code means that no control flow 
path reaches it, whereas dead code is on live control flow paths but its 
execution does not affect program output.


Diego.



More information about the Gcc-help mailing list