Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio Visual Studio 9.0错误C2051大小写表达式不是常量_Visual Studio_Compiler Errors - Fatal编程技术网

Visual studio Visual Studio 9.0错误C2051大小写表达式不是常量

Visual studio Visual Studio 9.0错误C2051大小写表达式不是常量,visual-studio,compiler-errors,Visual Studio,Compiler Errors,当我试图编译这段代码时,我得到了一个Case表达式Not Constant错误。我不明白为什么 while ((*datalen) == 0) crReturn(NULL); //error here st->len = (st->len << 8) + **data; 问题在于,当MSVC++被配置为为为其“编辑并继续”功能生成调试信息时,它做了一些非标准的事情(与它自己的文档相反),而这种非标准打破了Simon Tatham的协程宏中使用\uline\uu

当我试图编译这段代码时,我得到了一个
Case表达式Not Constant
错误。我不明白为什么

while ((*datalen) == 0)
    crReturn(NULL);  //error here
st->len = (st->len << 8) + **data;

问题在于,当MSVC++被配置为为为其“编辑并继续”功能生成调试信息时,它做了一些非标准的事情(与它自己的文档相反),而这种非标准打破了Simon Tatham的协程宏中使用
\uline\uuuu
的方式

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'.

所以你应该这么做。(事实上,我知道您已经这样做了,因为在我发布此答案之前,我们在评论中讨论了这一点:-)

此代码是否在
开关
语句中?如果不是,那么当MSVC++看到
案例
不在
开关
内时,可能会(令人困惑地)给出一个C2051错误;我手头没有MSVC++9的副本,但您可以通过在代码中的某个地方粘贴一个随机的
案例0:
来测试这一点,并查看从中得到的错误。(crReturn的实际预期用途是什么?)哦。你用的是西蒙·塔瑟姆的合作项目,是吗?在这种情况下,我禁不住想,你应该得到所有的痛苦:-)。您是否未能将
crBegin在函数的开始处和
crEnd最后?我注意到Simon Tatham的页面中有以下关于其协同程序宏的内容。“注意,VisualC++版本6不喜欢这个协同程序,因为它的默认调试状态(程序编辑和继续的数据库)对行宏有点奇怪。”我不希望这个问题出现在MSVC++的后期版本中,但是您可能会尝试关闭编辑和继续,看看是否有帮助。@ GarethMcCaughan这不是我的代码。这是putty的svn存储库中的源代码。我试图从VisualStudio9.0构建obj文件,并得到上面提到的错误。我想找出原因,然后克服它。该死。我突然想到,“禁用编辑并继续”可能是不明确的,所以让我明确一下我认为需要做什么:重要的是“调试信息格式”(在“C/C++->General”属性页上),它需要设置为“编辑并继续的程序数据库”以外的内容。如果这样做和重建都无济于事,那么我想我已经没有想法了;你可能想联系西蒙·塔瑟姆。。。
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'.