当我尝试编译此代码时,出现Case Expression Not Constant
错误。我无法弄清楚原因。
while ((*datalen) == 0)
crReturn(NULL); //error here
st->len = (st->len << 8) + **data;
函数crReturn()定义如下。
#define crReturn(z) \
do {\
*crLine =__LINE__; return (z); case __LINE__:;\
} while (0)
答案 0 :(得分:10)
问题在于MSVC ++在配置为其“编辑并继续”功能生成调试信息时执行非标准(与其自身文档相反)的操作,并且此非标准打破了__LINE__
的使用方式在Simon Tatham的协程宏中。
以下是PuTTY源代码中的注释对此的说法:
In particular, if you are getting `case expression not constant'
errors when building with MS Visual Studio, this is because MS's
Edit and Continue debugging feature causes their compiler to
violate ANSI C. To disable Edit and Continue debugging:
- right-click ssh.c in the FileView
- click Settings
- select the C/C++ tab and the General category
- under `Debug info:', select anything _other_ than `Program
Database for Edit and Continue'.
所以你应该这样做。 (事实上,我知道你已经这样做了,因为我在发表这个答案之前在评论中对此进行了讨论: - )。)