Afaik, every pair of { }
in the code creates a new scope. Even if it's used just for the sake of it without any if
, for
, function or other statement that demands it:
void myFun(void)
{
int a;
{
int local;
}
}
I started wondering - when the if
statement is written without using the braces (with 1-line body) does it still create a new scope?
voidmyFun(int a)
{
int b;
if (a == 1)
int tmp; // is this one local to if?
else
int tmp2; // or this one?
b = 2; // could I use tmp here?
}
Aucun commentaire:
Enregistrer un commentaire