PRB: Variables with Local Scope to Switch Won't Be Initialized (73850)
The information in this article applies to:
- Microsoft Visual C++ 1.0
- Microsoft Visual C++ 1.5
- Microsoft Visual C++ 2.0
- Microsoft Visual C++ 2.1
- Microsoft Visual C++ 4.0
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
This article was previously published under Q73850 SYMPTOMS
In Microsoft C, variables may be declared as local to a switch
statement by defining them within the braces that make up the switch.
They then have visibility and life for the duration of the switch
statement. However, because of the design of a switch block, they will
not be initialized when declared unless the variable is static or is
declared after a case label.
RESOLUTION
If you must declare an initialized variable that is local to the
switch statement and transient in duration, use brackets before and
after the switch and place the declaration outside the switch
statement.
Modification Type: | Major | Last Reviewed: | 12/12/2003 |
---|
Keywords: | kbLangC kbprb KB73850 |
---|
|