int *a;
if (1) {
int b = 123;
a = &b;
}
printf("%d\n", *a);
Because it compiles without warnings. Would it be OK if this were just a scope instead of an if?b
isn't used at any later pointb
is used later and allow thatMISRA:2012:18.6
I'm guessing if MISRA has a rule for this it's probably not there in any compiler by default{
int a;
do_smth_with(a);
}
int b;
do_smth_with(b);
And you never use a
outside that scope and you enable optimizations the compiler will reuse the same memory location I'm sure. That should prove that the compiler purposefully checks if a
is used outside the scope, right?