c++ - 这是 Visual Studio 2010 中的编译器错误吗?

标签 c++ visual-studio-2010 compiler-bug

我在这个条件中有一个错误:

while(CurrentObserverPathPointDisplacement > lengthToNextPoint && CurrentObserverPathPointIndex < (PathSize - 1) )
{
     CurrentObserverPathPointIndex = CurrentObserverPathPointIndex + 1;
     CurrentObserverPathPointDisplacement -= lengthToNextPoint;
     lengthToNextPoint = (CurrentObserverPath->pathPoints[min((PathSize - 1),CurrentObserverPathPointIndex + 1)] - CurrentObserverPath->pathPoints[CurrentObserverPathPointIndex]).length();
}

在 Release 模式下,它似乎陷入了无限循环。在 Debug模式下工作正常,或者当我在最后一行放置调试打印时更有趣

OutputInDebug("Here");

这是为条件本身生成的程序集:

            while(CurrentObserverPathPointDisplacement > lengthToNextPoint && CurrentObserverPathPointIndex < (PathSize - 1) )
00F074CF  fcom        qword ptr [dist]  
00F074D2  fnstsw      ax  
00F074D4  test        ah,5  
00F074D7  jp          ModelViewData::moveCameraAndCenterOnXYPlaneForwardBackward+27Eh (0F0753Eh)  
00F074D9  mov         eax,dword ptr [dontRotate]  
00F074DC  cmp         eax,ebx  
00F074DE  jge         ModelViewData::moveCameraAndCenterOnXYPlaneForwardBackward+27Eh (0F0753Eh)  
            {

您可以看到,对于第二个条件,它似乎将 bool 类型的函数参数 'dontRotate' 的值移动到 eax 中,然后与它进行比较,但 dontRotate 并没有在靠近那段代码的地方使用。

我知道这可能是一个有点小的数据,但我个人认为这是一个明显的编译器错误。但遗憾的是,我不确定如何将它提炼成一个足够独立的问题来实际生成错误报告。

编辑: 不是实际的减速,而是类型:

double CurrentObserverPathPointDisplacement;
double lengthToNextPoint;
int CurrentObserverPathPointIndex;
int PathSize;
vector<vector3<double>> CurrentObserverPath::pathPoints;

编辑2:

一旦我将调试打印语句添加到 while 的末尾,这就是生成的程序集,它不再表达错误:

            while(CurrentObserverPathPointDisplacement > lengthToNextPoint && CurrentObserverPathPointIndex < (PathSize - 1) )
00B1751E  fcom        qword ptr [esi+208h]  
00B17524  fnstsw      ax  
00B17526  test        ah,5  
00B17529  jp          ModelViewData::moveCameraAndCenterOnXYPlaneForwardBackward+2D6h (0B175A6h)  
00B1752B  mov         eax,dword ptr [esi+200h]  
00B17531  cmp         eax,ebx  
00B17533  jge         ModelViewData::moveCameraAndCenterOnXYPlaneForwardBackward+2D6h (0B175A6h)  
            {

最佳答案

这里:

while(/* foo */ && CurrentObserverPathPointIndex < (PathSize - 1) )
{
     CurrentObserverPathPointIndex = CurrentObserverPathPointIndex + 1;

因为这是循环中唯一的点(除非 min 做了一些非常讨厌的事情),其中 CurrentObserverPathPointIndex 被更改并且 CurrentObserverPathPointIndexPathSize 是相同大小的有符号整数(并且 PathSize 足够小以排除整数提升问题),其余的浮点摆弄无关紧要。循环最终必须终止(不过,如果 CurrentOvserverPathPointIndex 的初始值与 PathSize 相比较小,则可能需要相当长的时间)。

这只能得出一个结论;如果编译器生成的代码不会(永远)终止,那么编译器就错了。

关于c++ - 这是 Visual Studio 2010 中的编译器错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9387349/

相关文章:

c++ - 如何为队列重载 > 运算符

visual-studio-2010 - 如何将现有的子文件夹(有/没有子文件/文件夹)添加到解决方案中?

visual-studio-2010 - 字符串未被识别为有效的 bool 值。 - 与 C# 相关的错误。 GridView 复选框字段

C++ 初始化使用 "new"关键字分配的结构的对象成员

c++ - shared_ptr 删除器问题

c++ - 在 Ubuntu 中定位 Boost 库

visual-studio-2010 - 如何让 Visual Studio 在 BeforeBuild 处理后重新读取源文件?

gcc - GCC位域实现中的错误

c++ - (默认)为每个可变类型构造一个对象

c++ - Lambda 适用于最新的 Visual Studio,但在其他地方不起作用