PRB: C2361: Initialization of "i" Is Skipped by "Default"Last reviewed: August 8, 1997Article ID: Q87013 |
The information in this article applies to:
SYMPTOMSAn attempt to compile the Sample Code below as a C++ file with one of the compilers listed above will fail and generate the following message:
error C2361: Initialization of 'i' is skipped by 'default' label CAUSEThis error occurs because the "case" and "default" labels do not limit scope; instead, each one is a structured goto and suffers the same limitations with respect to control flow. In the example below, the symbol "i" remains in scope in subsequent "case" clauses. However, if the flow of control is transferred to these clauses, the object was not initialized. The C++ language requires determining possible control flow errors through a static analysis of the code.
RESOLUTIONTwo possible solutions are:
MORE INFORMATIONThe compiler-generated error described above is correct. This behavior is required by the C++ language.
Sample Code
/* Compile options needed: /Tp */ int var; void main() { switch (var) { case 1: // do something break; case 2: int i = 1; break; default: // do something else break; } } |
Additional query words: 8.00 8.00c 9.00 9.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |