编译问题 case expression not constant
来源:互联网 发布:河南836软件孵化器 编辑:程序博客网 时间:2024/05/16 08:21
最近遇到了一个宏:
#define crReturn(z) /
do {/
crLine=__LINE__; return (z); case __LINE__:;/
} while (0)
用VS2003编译的时候,提示 error C2051: case expression not constant
按照宏替换的道理,__LINE __应该是会换成行号,是整数常量啊,没有问题啊,怎么会提示不是常量呢。
想了半天没解决,到网上搜了个答案:编译器配置的问题,只需要在编译配置页C++/general/debug info format中设置为/Zi,不使用/ZI,就可以了。原文链接:http://www.codeguru.com/forum/archive/index.php/t-198413.html
原文说是VC的bug,想了下,不知道算不算BUG,可以这样解释:
因为使用/ZI表示编辑并继续运行,所以__LINE__应该可以中途变动,必然不能是常量,
而case要求__LINE__在编译之前就决定为常数,不能是动态修改的,这样两者就相冲突。
可能编译器没有把__LINE__直接变成整数常量,而是一个变量,这样只能满足/ZI的要求,这样就不能满足case的要求的常量。
不知道VC怎么设计的,就只能猜到这种程度。
- 编译问题 case expression not constant
- 编译问题 case expression not constant
- error C2051: case expression not constant ?
- switch case constant expression required
- constant expression required 的问题
- Keil提示错误error c221: non-constant case/dim expression
- constant expression required-case后参数报错
- .size expression for apf_page_fault does not evaluate to a constant
- size expression for do_hypervisor_callback does not evaluate to a constant
- size expression for do_hypervisor_callback does not evaluate to a constant
- [问题记录]编译时出现 initializer element is not constant 错误
- debug03:“case expressions must be constant expression”报错的破解
- !!!Constant Expression (From MSDN)
- Constant expression required
- case expressions must be constant expressions 的问题
- initializer element is not constant 问题
- initializer element is not constant 问题
- 数组编译时出错error C2057: expected constant expression,以及解决办法
- 获得系统特殊路径函数SHGetSpecialFolderLocation()获取当前用户桌面
- SHGetSpecialFolderLocation
- PHP Json函数不能处理中文的解决办法
- 堆和栈
- VCC、VDD、VEE、VSS等有关电源标注的区别
- 编译问题 case expression not constant
- 【百科】逻辑代数
- 使用查找对话框后,另一对话框的位图背景加载失败
- android开发中经常看到@Override是什么意思呢?
- 动态生成控件并取值
- 面朝大海,春暖花开
- 软件工程视频学习笔记(三十七)
- 软件工程视频学习笔记(三十八)
- 软件工程视频学习笔记(三十九)