CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Aug 2012
    Posts
    2

    Compiler bug - Fast Code does not give same results as No Optmization

    The following program gives different results when comiled for Fast Code versus No Optimization.
    When running in the IDE the results are the same as No Optmization.
    But, when compiled for Fast Code, the exe gives different results.
    In ths example, the after setting the FltData array value, when reading the same value it does not return the value that was just set.
    Changing little things in the code changes the results - like removing the for loop, for example.

    If this one example shows that the results can be incorrect with FAST CODE optimization, how can I trust Fast Code for any of my projects?


    Code:
    Option Explicit
    
    Const COL_FLTS = 1
    Const COL_FTIME = 2
    
    Public FltData(100, 7, 1) As Long
    Public xCOL_FTIME As Long, xCOL_FLTS As Long
    
    
    Sub Main()
        Dim x As Long, j As Long
        Dim rw As Long, mon As Long, comment As String
        rw = 1
        mon = 0
        comment = "main "
        xCOL_FLTS = 1: xCOL_FTIME = 2
        
    Call testLongArray(rw, mon, "testlong #1")
    'Call testLongArray(rw, mon, "testlong #2")
    
    
    FltData(rw, COL_FLTS, mon) = FltData(rw, COL_FLTS, mon) + 1000
    x = FltData(rw, COL_FTIME, mon) + 100
    FltData(rw, COL_FTIME, mon) = x
    For j = 1 To 12
    Next j
    If x <> FltData(rw, COL_FTIME, mon) Then
        MsgBox (comment & " no joy " + Str(x) + Str(FltData(rw, COL_FTIME, mon)) + Str(FltData(rw, COL_FLTS, mon)))
    Else
        MsgBox (comment & " OK " + Str(x) + Str(FltData(rw, COL_FTIME, mon)) + Str(FltData(rw, COL_FLTS, mon)))
    End If
    
    Call testLongArray(rw, mon, "testlong #3 ")
    End Sub
    
    Function testLongArray(ByVal rw As Long, ByVal mon As Long, ByVal comment As String)
        Dim j As Long, x As Long
        
    FltData(rw, COL_FLTS, mon) = FltData(rw, COL_FLTS, mon) + 10
    x = FltData(rw, COL_FTIME, mon) + 100
    FltData(rw, COL_FTIME, mon) = x
    For j = 1 To 12
    Next j
    If x <> FltData(rw, COL_FTIME, mon) Then
        MsgBox (comment & " no joy" + Str(x) + Str(FltData(rw, COL_FTIME, mon)) + Str(FltData(rw, COL_FLTS, mon)))
    Else
        MsgBox (comment & " OK " + Str(x) + Str(FltData(rw, COL_FTIME, mon)) + Str(FltData(rw, COL_FLTS, mon)))
    End If
    
    End Function
    Last edited by kreniska; September 4th, 2012 at 10:55 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured