Announcement

Collapse
No announcement yet.

Compiler error?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Compiler error?

    I am getting very strange results. If I use the result of a method in an expression, I get the wrong answer. It doesn't matter what the expression is, I still get the same (incorrect) result.

    If I just use it to set the local variable, it is correct(234). The same thing happens if I use a property instead of a method. ODB is a method that does an OutputDebugString.

    I need to know if this is a restriction on the use of a method result or if my code is somehow causing this odd behavior, what tools can I use to find out where the problem is?

    There is way too much code to publish it all here.

    Thanks...
    Garry

    Code:
    LOCAL nDc as LONG
    nDc = (newDirMap.GetCount()) - 1
    ODB "nDc1= " + str$(nDc)
     
    nDc = (newDirMap.GetCount())
    nDc = nDc - 1
    ODB "nDc2= " + str$(nDc) 
     
    nDc = (newDirMap.GetCount()) - 2
    ODB "nDc3= " + str$(nDc)
     
    nDc = (newDirMap.GetCount()) - 500
    ODB "nDc4= " + str$(nDc)
    The output is:
    nDc1= -4692
    nDc2= 234
    nDc3= -4692
    nDc4= -4692

  • #2
    I did find the following in my code within one of my classes:

    Code:
      Method
      End Method

    Could this cause this kind of random/undefined behavior? Removing this has not changed the behavior above. I'm simply coding around it (see nDc2 in previous post).

    Is there something like lint available for PB?

    Comment


    • #3
      Originally posted by garry star View Post
      ..
      There is way too much code to publish it all here.

      Thanks...
      Garry
      You could always upload it as an attachment (maybe in zip form) and fresh eyes could look at it.

      ============================================
      And if there be no meeting past the grave,
      If all is darkness, silence, yet 'tis rest.
      Be not afraid, ye waiting hearts that weep,
      For still He giveth His beloved sleep,
      And if an endless sleep He wills, so best.
      Henrietta Anne Huxley,
      written on her husband
      Thomas Henry Huxley's tombstone.
      ============================================
      It's a pretty day. I hope you enjoy it.

      Gösta

      JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
      LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

      Comment


      • #4
        Sorry Gösta-

        There's over 300k of source and I can't upload it all anyways due to non-disclosure issues.

        I was hoping for someone from PowerBasic to provide some ideas on how to find this problem.

        Tack...

        Garry

        Comment


        • #5
          Same here

          I am getting the exact same problem in my system using PB 9.01. I submitted a description of this to PB support early this morning, but like you, could not submit a clean small example as it only happens when I have a large amount of code. Like you, I have found that direct assignments work, but it fails in expressions or IF statements. I am currently trying a work around of putting each of my classes into their own separately compiled .dll files to make each compile smaller and have it work like it did before my code grew - I'm hoping that works, as I'm stuck otherwise.

          Comment


          • #6
            The only reasonable answer is memory corruption. You have code in your program which incorrectly changes something "important" which it should not.

            It could be an array bounds error, pointer misuse, return without a gosub, errant assembler code, or many other things. The expression is not the error, it's the symptom of something which erroneously happened earlier. You need to examine your code carefully to find the underlying issue which causes it.

            It's not possible to find the cause without seeing the offending code.

            Best regards,

            Bob Zale
            PowerBASIC Inc.

            Comment


            • #7
              Originally posted by Colin Schmidt View Post

              putting each of my classes into their own separately compiled .dll files to make each compile smaller and have it work like it did before my code grew - I'm hoping that works, as I'm stuck otherwise.
              It's highly unlikely that will help at all. Even if it succeeds, the results would be fleeting. You won't be fixing the core problem... you'll only be moving code around so that the memory you corrupt isn't as "important" at the moment. Until you find the core problem, it will recur later.

              Best regards,

              Bob Zale

              Comment


              • #8
                Add the following to your program, then execute normally...

                #DEBUG ERROR ON
                #DEBUG DISPLAY ON

                It's just possible it might detect an unhandled exception condition.

                Best regards,

                Bob Zale

                Comment


                • #9
                  I was hoping for someone from PowerBasic to provide some ideas on how to find this problem.
                  How about some thoughts from a mere user? (BTW, I think users of the compiler are probably better at finding bugs than are the compiler developers. After all, who USES the compiler more?)

                  First thing you do, change the order of those four posted statements around.. which one does the inline expression in what order.

                  Then your ry a loop... just run from --0000001 to +1000000 or so like
                  Code:
                  FOR Z = some_negative_number to some_positive_number
                      nDc = (newDirMap.GetCount()) - Z
                      ODB  USING$("With expression Z #  #", Z, nDC) 
                  
                      nDc = (newDirMap.GetCount())
                      nDc = nDc - Z
                     ODB  USING$("With Substraction Z #  #", Z, nDC)  
                  NEXT
                  If you are lucky, doing enough of these will force some kind of error somewhere and your program will fail and you'll be able to find the problem by reviewing the TRACE.

                  There's over 300k of source and I can't upload it all anyways due to non-disclosure issues.
                  Send compilable and executable version to PB. I've sent tons of proprietary code to them over the years; it's not at risk at all.

                  Lastly.... start structuring your programs so that you don't need 300K of source code to debug it. I think you will find here enough 'war stories' about guys who discovered a programming error while creating the much-coveted "compilable example demonstrating the problem." Beat the rush by writing code which you CAN 'unit test.'

                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    I found a local variable in one file with the same name as a class method in another file. Should that be a problem?

                    Is there any concept of a link map? My Windows Event log has the offset of my crash but I don't know how to find it in PB.

                    Comment


                    • #11
                      Even if there were such a thing as a link map, where you crash is not necessarily where the error is! There's lots of threads here covering this subject.

                      On local variable same as class name thing... I don't see that it should make a difference, but how long can it take to do a 'search and replace' in ONE procedure and give it a try?
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment

                      Working...
                      X