Search

Visual C++ 2010 Express - Błąd optymalizacji (optimization bug) by Rvdy

Resolved
as External Help for as External

1
0
Sign in
to vote
Type: Bug
ID: 780163
Opened: 2/27/2013 2:55:30 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug

Problem występuje podczas kompilacji i uruchomienia programu w wersji Debug.

Kod, gdzie wystepuje problem:
double dbRadius = sqrt((double)(dwVarX*dwVarX+dwVarY*dwVarY));
if (dbRadius >= 20 && dbRadius <= 100)
{
double dbAngle = acos(dwVarY/dbRadius)*(dwVarX >= 0)?(1):(-1);
nMousePosH = (LONG)floor(dbAngle*7/3);
nMousePosV = (LONG)floor((90-dbRadius)*3);
...
}

Zauważyłem, że gdy zostanie zapisana linia inicjalizująca zmienną, a po niej linia porównująca tą zmienną z paroma wartościami, kompilator optymalizuje te linie usuwając zmienną oraz porównując tymczasowo obliczoną wartość. Niestety w moim przypadku nie zostało wykryte ponowne użycie tej zmiennej wewnątrz bloku. W wersji Debug wartość ta zostaje przyrównana do 0.

---------------------

The problem occurs during compilation and running the application in Debug mode.

The code where the problem is:
double dbRadius = sqrt((double)(dwVarX*dwVarX+dwVarY*dwVarY));
if (dbRadius >= 20 && dbRadius <= 100)
{
double dbAngle = acos(dwVarY/dbRadius)*(dwVarX >= 0)?(1):(-1);
nMousePosH = (LONG)floor(dbAngle*7/3);
nMousePosV = (LONG)floor((90-dbRadius)*3);
...
}

I noticed that, when the line which initialize a variable followed by if statement will be written, the compiler optimizes this lines by removing a variable from memory, and using temporary calculated value. Unfortunately, in this case later use of this variable within the block has not been detected. In Debug mode this variable was evaluated to 0.

========== EDIT ==========

Problem został rozwiązany, przez przypadek pomyliłem nazwy zmiennych i wychodził zupełnie inny wynik. Podejrzewałem błąd, ponieważ nie mogłem odczytać wartości zmiennej w oknie "watch". Program działa teraz bez zarzutu, przepraszam za problem.

The problem was solved. Accidentaly I misspelled variable name and that is why I was different result. I suspected an error, because I could not read the value of the variable in "watch" window. The program works fine now, sorry for the problem.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

Visual Studio 2012

Steps to reproduce

PROBLEM SOLVED
double dbRadius = sqrt((double)(dwVarX*dwVarX+dwVarY*dwVarY));
if (dbRadius >= 20 && dbRadius <= 100)
{
double dbAngle = acos(dwVarY/dbRadius)*(dwVarX >= 0)?(1):(-1);
nMousePosH = (LONG)floor(dbAngle*7/3);
nMousePosV = (LONG)floor((90-dbRadius)*3);
...
}

Product Language

Polish

Operating System

Windows XP

Operating System Language

Polish

Actual results

Problem solved
brak wartości zmiennej dbRadius wewnątrz bloku

no variable dbRadius inside the block

Expected results

Problem solved
Zmienna dbRadius powinna być dostępna i mieć wartości z przedziału od 20 do 100

Variable dbRadius should be available and have value from 20 to 100
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 2/27/2013 at 7:32 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. At this time, we only provide support in the English language.

- For urgent issues , please contact support directly at http://support.microsoft.com or call 1-800-MICROSOFT for assistance.
Posted by Microsoft on 2/27/2013 at 7:31 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. At this time, we only provide support in the English language.

- For urgent issues , please contact support directly at http://support.microsoft.com or call 1-800-MICROSOFT for assistance.
Posted by Microsoft on 2/27/2013 at 3:50 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.