[英]Is this a compiler error in Visual Studio 2010?
我在這種情況下有一個錯誤:
while(CurrentObserverPathPointDisplacement > lengthToNextPoint && CurrentObserverPathPointIndex < (PathSize - 1) )
{
CurrentObserverPathPointIndex = CurrentObserverPathPointIndex + 1;
CurrentObserverPathPointDisplacement -= lengthToNextPoint;
lengthToNextPoint = (CurrentObserverPath->pathPoints[min((PathSize - 1),CurrentObserverPathPointIndex + 1)] - CurrentObserverPath->pathPoints[CurrentObserverPathPointIndex]).length();
}
在“釋放”模式下,它似乎陷入了無限循環。 在調試模式下工作正常,或者在最后一行放置調試打印內容時更有趣
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:
一旦我將debug print語句添加到一段時間的末尾,這就是生成的程序集,它不再表示錯誤:
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;
由於這是更改CurrentObserverPathPointIndex
的循環中唯一的點(除非min
確實做得很討厭),並且CurrentObserverPathPointIndex
和PathSize
都是相同大小的有符號整數(並且PathSize
小得可以排除整數提升問題),因此其余的浮動點擺弄是無關緊要的。 循環必須最終終止(但是,如果CurrentOvserverPathPointIndex
的初始值CurrentOvserverPathPointIndex
PathSize
,則可能要花很長時間)。
這僅得出一個結論。 如果編譯器生成的代碼永遠不會終止,則說明編譯器是錯誤的。
看起來PathSize
在循環中沒有變化,因此編譯器可以在循環之前計算PathSize - 1
,並且無論使用dontRotate
,巧合地使用與dontRotate
相同的內存位置。
更重要的是, CurrentObserverPath->pathPoints
中有多少個元素?
您的循環條件包括此測試:
CurrentObserverPathPointIndex < (PathSize - 1)
在您的循環中是此分配:
CurrentObserverPathPointIndex = CurrentObserverPathPointIndex + 1;
接下來是這個進一步增加的下標:
[min((PathSize - 1),CurrentObserverPathPointIndex + 1)]
也許您的代碼似乎可以在調試模式下工作,因為隨機的未定義行為似乎可以工作嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.