1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
int x1, x2, x3;
int g()
{
return x1 + x2 + x3; /* 1. uses x3 before definition */
}
int f()
{
int loc;
if (3 > 4)
{
loc = 3;
return x1; /* 2, 3, 4. bad --- x1 not defined, x2, x3 not defined */
}
else
{
if (4 > 6)
{
loc = x1; /* 5. x1 not defined */
loc = g(); /* 6. bad --- x1, x2 not defined before call (defines x2 and x3) */
loc = x3;
}
else if (2 > 3)
{
loc = x3; /* 7. x3 not defined */
x1 = 6;
x2 = 7;
return g();
}
else
{
x1 = 6;
x2 = 7;
return 12; /* 8. returns with x3 not defined */
}
}
return 12;
/* No errors to report. Previously,
[9, 10. returns with x2 and x3 undefined (x1 IS defined on all branches!)]
but this is not correct; all branches that can reach the return do define
x1, x2 and x3.
*/
}
int h (void)
{
return x1; /* okay */
}
|