Created
January 6, 2021 00:50
-
-
Save Shaun289/371df36ddee22901b7a5b78f2aaf57cb to your computer and use it in GitHub Desktop.
c++ switch case error: crosses initialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum MODULE_TYPE { | |
TYPE_A = 0, | |
TYPE_B, | |
TYPE_C, | |
TYPE_D, | |
TYPE_E, | |
TYPE_F, | |
TYPE_G, | |
TYPE_H, | |
TYPE_I, | |
TYPE_MAX_CNT, | |
}; | |
#define USE_FUNC | |
char test() | |
{ | |
uint32_t _type = TYPE_G; | |
switch (_type) { | |
case TYPE_A: return 'a'; | |
case TYPE_B: return 'b'; | |
case TYPE_C: return 'c'; | |
case TYPE_D: return 'd'; | |
case TYPE_E: return 'e'; | |
case TYPE_F: | |
// 에러 발생 crosses initialization of ‘bool b’ | |
// 오래된 컴파일러에서는 에러가 발생하지 않으나 아래 TYPE_G 부터는 jump하지 않는다. | |
bool b = true; | |
#if defined(USE_FUNC) | |
b = false; | |
#endif | |
return b?'f':'F'; | |
case TYPE_G: return 'g'; | |
case TYPE_H: return 'h'; | |
case TYPE_I: return 'i'; | |
} | |
return 'a'; | |
} | |
int main() | |
{ | |
test(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment