-
-
[旧帖]
[求助]switch-case 中变量声命问题,求深入讲解下。
0.00雪花
-
发表于:
2012-5-3 18:48
1354
-
[旧帖] [求助]switch-case 中变量声命问题,求深入讲解下。
0.00雪花
大家看下面的代码,红色部分在VC6中会报错:error C2360: initialization of 'hwnd' is skipped by 'case' label
switch(uMsg) {
case WM_INITDIALOG:
[COLOR="Red"]HWND hwnd = GetDlgItem(hwndDlg,IDC_NAME); [/COLOR]
// TODO: Place code here.
break;
case WM_CLOSE:
EndDialog(hwndDlg,0);
break;
}
改成下面这种就没问题:
switch(uMsg) {
case WM_INITDIALOG:
[COLOR="Red"]HWND hwnd;
hwnd = GetDlgItem(hwndDlg,IDC_NAME);[/COLOR]
// TODO: Place code here.
break;
case WM_CLOSE:
EndDialog(hwndDlg,0);
break;
}
这两种声名的方式,到底差别在那,编译器实现switch-case语句为什么第一种就会报错,感觉没什么不同呀。不知道怎么问好,能从变量的内存分布分配方面讲解下最好,或者说这只是编译器的一个小BUG。碰到这种错误好几次了,一直纠结啊
[结贴啦,自己找到了点资料,有兴趣的可以去看下]http://blog.csdn.net/tonywearme/article/details/7075809
[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法