简体   繁体   English

不能在监视窗口中评估包含名为“ by”的术语的Visual Studio表达式

[英]Visual Studio expression containing a term named “by” cannot be evaluated in the watch window

Consider my C++ code below: 考虑下面的我的C ++代码:

int _tmain(int argc, _TCHAR* argv[])
{
    int by = 10;
    printf("%d\n", by);

    int bx = 20;
    printf("%d\n", (by + bx));

    return 0;
}

which works fine. 效果很好。 The funny thing is with the "by" variable. 有趣的是“ by”变量。 If I try to add a watch for a simple expression that contains by, the result will be CXX0030: Error: expression cannot be evaluated. 如果我尝试为包含的简单表达式添加监视,结果将为CXX0030:错误:无法评估表达式。

For example, on a breakpoint on return 0 , if I add the following watches I get the results mentioned: 例如,在return 0的断点上,如果我添加以下手表,则会得到提到的结果:

by : 10
bx : 20
by + 5 : CXX0030: Error: expression cannot be evaluated
bx + 5 : 25
by + bx : CXX0030: Error: expression cannot be evaluated
(by) + bx : 30
by + (bx) : CXX0030: Error: expression cannot be evaluated
bx + (by) : CXX0014: Error: missing operrand

This happens on VS2010, VS2008 on multiple computers. 这在多台计算机上的VS2010,VS2008上发生。

So, more out of curiosity, what is happening with "by"? 因此,出于好奇,“ by”发生了什么? Is it some kind of strange operator? 是某种奇怪的运算符吗? Why doesn't bx get the same treatment? 为什么bx没有得到相同的待遇?

(I've tried google on this but it is quite difficult to get some relevant hits with terms like "by") (我已经尝试过在google上进行此操作,但是很难获得诸如“ by”之类的相关匹配)

Intrigued by this, I did some digging. 对此我很感兴趣,我做了一些挖掘。 From this link , we see that the native C/C++ expression evaluator in the debugger handles Assembly-Language expressions; 通过此链接 ,我们可以看到调试器中的本机C / C ++表达式评估器可以处理汇编语言表达式。 following the Assembly-language link , we discover that BY is short for BYTE in an an Assembly-Language expression. Assembly-language链接之后 ,我们发现BY在Assembly-Language表达式中是BYTE的缩写。 So just another Microsoft cock-up 因此,这只是微软的又一个秘诀

What you're seeing here is the C++ Expression Evaluator's implementation of the BY operator. 您在此处看到的是C ++表达式评估器对BY运算符的实现。 Your use of the expression BY is being interpreted as an operator instead of a local variable. 您对表达式BY使用将被解释为运算符,而不是局部变量。

Reference: http://msdn.microsoft.com/en-us/library/56638b75.aspx 参考: http : //msdn.microsoft.com/en-us/library/56638b75.aspx

A lot of discussion has gone into whether or not this behavior is a bug or by design. 对于此行为是错误还是设计使然,已经进行了很多讨论。 Unfortunately that can only be truly answered by the people who implemented the feature. 不幸的是,只有实现该功能的人员才能真正回答。 As dissatisfying as it is for this scenario there could be valid reasons why this was explicitly done (costs of disambiguating comes to mind). 尽管对于这种情况不满意,但可能有明确理由这样做的正当理由(让人想到消除歧义的成本)。 Or this could simply be an oversight of the implementor. 或者这可能只是对实施者的监督。 Again only they know the answer. 再次只有他们知道答案。

If this does feel like a bug to you then please do file a bug on connect. 如果对您来说这确实是个错误,请在连接时提交错误。 This is the best way to get your opinion heard and very likely the team has never received any feedback on this behavior (could not find any in my searches). 这是表达您的意见的最佳方法,并且很可能团队从未收到有关此行为的任何反馈(在我的搜索中找不到任何反馈)。

What you're running into is the debugger's 'memory operator' : 您遇到的是调试器的“内存操作符”

In native C++, debugger expressions do support the following additional operators: 在本机C ++中,调试器表达式确实支持以下其他运算符:

  • The context operator ({ }) to specify the context of a symbol. 上下文运算符({})用于指定符号的上下文。 For more information, see Context Operator (C/C++ Language Expressions). 有关更多信息,请参见上下文运算符(C / C ++语言表达式)。

  • Memory operators ( BY , WO, and DW) to access memory. 内存操作员( BY ,WO和DW)访问内存。 Memory operators have the lowest precedence of any operator. 内存运算符的优先级最低。 The memory operators are useful mainly in debugging assembly-language code. 内存运算符主要在调试汇编语言代码中很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM