Announcement

Collapse
No announcement yet.

Bug in Array Sort

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

  • Bug in Array Sort

    If count is zero and index is one, then PBCC apparently (based on the amount of time taken) attempts to sort the entire allocated array ... no matter how big that is. For example, the following program has a long wait between the two print statements. If there are no elements to sort, I would expect array sort to run extremely fast and therefore consider this a bug.

    #STACK 4194304
    type t_XCH
    SK as string*27
    xty as long
    end type ' t_XCH
    global mXCH as long, nXCH as long, XCH() as t_XCH
    function PBMAIN as long
    mXCH = 1048576
    nXCH = 0
    redim XCH(mXCH)
    print "sorting empty array ..."
    array sort XCH(1) for nXCH, ascend
    print "... sorted empty array"
    end function

  • #2
    Actually, there's a technique to avoid sorting an array. That would be: Don't execute an ARRAY SORT statement. Just leave it out completely.

    A COUNT value of zero is used by PowerBASIC to indicate that there is no limit placed on the number of items to be sorted. We recommend that you avoid that circumstance if at all possible.

    Best regards,

    Bob Zale
    PowerBASIC Inc.

    Comment


    • #3
      Well, there still is a bug.

      With #DEBUG ERROR ON, ARRAY SORT is not returning an ERR when specifying a start index of 1, which in code shown is beyond the UBOUND of the target array.

      ARRAY SORT should have caught that, set ERROR =9 and not even attempted the sort at all.

      For that matter, I don't know how the sort could have NOT GPFed, since every array element access SORT attempted was accessing an element beyond the current UBOUND of XCH().
      Last edited by Michael Mattias; 19 Apr 2009, 09:47 AM.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Oops. My bad. Those "Ms" and "Ns" all look alike.

        When UBOUND (XCH,1) is less than the starting index, ARRAY SORT indeed does (promptly) return ERROR=9.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Bob Zale's note that count = zero in effect sorts the entire allocated area completely explains what I observed. Many thanks, Bob.

          Bob's other comment is also valuable. I have no business sorting an array that has count of one or less.

          Comment

          Working...
          X