Unreachable code

Code was found that cannot be executed.

The presence of unreachable code may indicate a misspelling, a bad automated merge, or some other form of source code corruption. Unreachable code should be examined to ensure that this code was intended to be unreachable.

Sometimes, developers deliberately create unreachable code with the expectation that the compiler will remove that code during optimization. Some kinds of preprocessing macros can have this effect. In cases like this, this diagnostic can be safely ignored.

ID

Observation

Description

1

Unreachable code

The code that will never be executed

Examples


#include <stdio.h>

int x;

int main(int argc, char **argv)
{
    if (x != 0) {
        // statement is unreachable because x must be zero
        printf("Default initialization to zero doesn't work\n");
    }
    return 0;
}
        

Copyright © 2010, Intel Corporation. All rights reserved.