4 ms·
EDIT: I sit corrected. My post is wrong. No, you can't, and no they don't. lock(lk_var) { lock(lk_var2) { var = var2; } }
by VikingCoder 13y ago
EDIT: I sit corrected. My post is wrong.
No, you can't, and no they don't.
lock(lk_var) {
lock(lk_var2) {
var = var2;
}
}
That expands to:
for(int i=0; (i < 1) && !lk_lock(lk_var); lk_unlock(lk_var), i++)
{
for(int i=0; (i < 1) && !lk_lock(lk_var2); lk_unlock(lk_var2), i++)
{
var = var2;
}
}
You end up with an i scoped inside another i.
- plorkyeran 13y agoC++ has variable shadowing, so that works correctly. for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) { printf("hello\n"); } } prints hello 25 times.
- VikingCoder 13y agoOh right. My brain was stuck in another language. Wow, I forgot how much I'd forgotten about C++.
- JoeAltmaier 13y agoActually that's just C (name nesting)