Hi folks,

This one has me and a couple of colleagues stumped. Can anybody explain why
attaching (or not attaching) a debugger should make any difference to the
results produced by the following VB.NET console app?

Try running the app in Debug mode, first starting with F5 and then starting
with Ctrl-F5. Then run it in Release mode, also with F5 followed by Ctrl-F5.

Whenever the program is started with F5, the last WriteLine prints True as
I would expect. With Ctrl-F5, the result is False. I understand that this
is because of the usual precision problem when dealing with the Double
type, but why should attaching a debugger (rather than compiling with code
optimization) cause a different result?

Regards,

Mark

Option Strict On

Sub Main()

    Dim dblOne As Double = Math.Log(8, 2)
    Dim dblTwo As Double = Math.IEEERemainder(dblOne, 1)

    'DEBUG or RELEASE configuration
#If Debug = True Then
    Console.WriteLine("DEBUG configuration")
#Else
    Console.WriteLine("RELEASE configuration")
#End If

    'Started with F5 or Ctrl-F5?
    Console.WriteLine("Debugger attached? " & Debugger.IsAttached.ToString)

    Console.WriteLine("dblOne = " & dblOne.ToString)
    Console.WriteLine("dblTwo = " & dblTwo.ToString)
    Console.WriteLine("dblTwo = 0? " & (dblTwo = 0).ToString)

    Console.ReadLine()

End Sub

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to