1

My code :

decimal fAnzahlAktuell = 12;
decimal fMenge = 2;
decimal fAnzahlReserviertPickpos = 0;

decimal a = ((decimal)(fAnzahlAktuell - fAnzahlReserviertPickpos)) > fMenge ? fMenge : (decimal)(fAnzahlAktuell - fAnzahlReserviertPickpos);
decimal b = (decimal)((fAnzahlAktuell - fAnzahlReserviertPickpos) > fMenge ? fMenge : (decimal)(fAnzahlAktuell - fAnzahlReserviertPickpos));

When i compile using x86 -> a and b both = 2

When i compile using anycpu -> a = 2 and b = 0

Can anybody explain why?!

EDIT : I am using VS2010 , .NET 4.0 on Windows 7 x64

enter image description here

Marius Bancila
  • 16,053
  • 9
  • 49
  • 91
Mohnkuchenzentrale
  • 5,745
  • 4
  • 30
  • 41
  • 1
    It gives same results for Any CPU vs x86 on Visual Studio 2012. – Habib Apr 15 '14 at 14:38
  • Per defintion no difference - but this does not rule out an error in one of the runtimes. – TomTom Apr 15 '14 at 14:39
  • 1
    Are you just seeing this in the debugger? Are you running in Release mode? Do you do anything with the variable `b` afterwards? Does `b` still show as 0 if you print it to the screen? You might be seeing the result of aggressive optimization. – Baldrick Apr 15 '14 at 15:23

2 Answers2

2

Resolved it myself. It is a bug in VS2010 with x64 debugger ...

https://connect.microsoft.com/VisualStudio/feedback/details/655793/edit-this-entry-misreporting-of-variable-values-when-debugging-x64-code-with-the-visual-studio-2010-debugger

Mohnkuchenzentrale
  • 5,745
  • 4
  • 30
  • 41
1

It's a quirk of the debugger.

The mis-reported value that you are observing can only be seen in the debugger. If you output the values, for instance to the console, then you will see that they are both 2 for all configurations.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490