TITLE: switch statements and variable initialization PROBLEM: emzee@telerama.lm.com switch(x) { case 1: int y = x; [ modified from original ] ... break; case 2: etc... gave me the message: initilization of y missed by case stmt or some such thing. However, switch(x) { case 1: { int y=x; [ modified from original ] ... break; } case 2: compiles and executes fine! RESPONSE: 76001.2500@compuserv.com (Scott J. Baierl) It doesn't have anything to do with brackets. RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 13 Oct 95 Yes, it does. RESPONSE: SJB ?All execution paths of a switch statement must have the same variable declarations, so they must be declared before the switch. RESPONSE: SC No, there is no such rule. The C++ rule is that you cannot jump past the initialization of a variable unless you bypass the entire block containing the initialization. (See the ARM, p86 and p91.) The original example did not have that problem, and should not have caused a compiler complaint, so I modified it slightly to demonstrate the rule. (I assume the original article did not copy the offending code exactly, since it was also missing the needed left brace after the "switch" headers.) In the first example, taking the 'case 2' leg would leave variable 'y' in scope, but without having been initialized. That would violate the rule, so the code is invalid. In the second example, taking the 'case 2' leg bypasses the entire block containing 'y', so no rule is violated.