Hello.
I cannot find the definition on how this is handled.Code:void Blah() { static int i; ... if(case) { static int i; ... } }
Apparently the VC 2003 compiler handles this differently compared to the 2008 version.
Thanks a lot for you help!
Hello.
I cannot find the definition on how this is handled.Code:void Blah() { static int i; ... if(case) { static int i; ... } }
Apparently the VC 2003 compiler handles this differently compared to the 2008 version.
Thanks a lot for you help!
The innermost int i should hide the outermost int i, so that the outermost variable is not visible in the if-case. I don't see anything about how static would make those two variables the same.
Well, "shall" if you want to be more formal about it. The standard says this:
Since there are no exceptions listed for static-linkage variables, I would see no reason for them to be handled differently.Originally Posted by ISO C++ 3.3, para 1
Edit: I said static-linkage; I mean static duration. Static variables at block scope still have no linkage (static only specifies external linkage at namespace scope according to 3.5).
Last edited by tabstop; 10-28-2008 at 04:33 PM.
Okay.
I remember to have heard something about the MS compilers not following the standard with variable scopes.
Does anyone know about this particular case with static variables (using max compiler/linker optimizations)?
> Does anyone know about this particular case with static variables (using max compiler/linker optimizations)?
So are you saying that one of them is wrong, based on the quote from the standard provided by tabstop?
Are they consistent with the standard (or each other) at lower optimisation settings?
Are they consistent with the standard (or each other) for non-static variables?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.