Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
C6259
Collapse the table of content
Expand the table of content

C6259

warning C6259: labeled code is unreachable: (<expression> & <constant>) in switch-expr cannot evaluate to <case-label>

This warning indicates unreachable code caused by the result of a bitwise-AND (&) comparison in a switch expression. The case statement that matches the constant in the switch expression is only reachable; all other case statements are not reachable.

The following sample code generates this warning because the expression switch (rand() & 3) cannot evaluate to case label (case 4):

#include <stdlib.h>

void f()
{
     switch (rand () & 3) {
        case 3:
            /* Reachable */
            break;
        case 4:
            /* Not reachable */
            break;
        default:
            break;
    }
}

To correct this warning, remove the unreachable code or verify that the constant used in the case statement is correct. The following code removes the unreachable case statement:

#include <stdlib.h>

void f()
{
     switch (rand () & 3) {
        case 3:
            /* Reachable */
            break;
        default:
            break;
    }
}
Show:
© 2015 Microsoft