Announcement

Collapse
No announcement yet.

Strange behavior of ARRAY INSERT

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

  • Strange behavior of ARRAY INSERT

    I have come across some stange behavior of ARRAY INSERT. The following code
    inserts a user-defined type in a small array of user-defined types. I use
    MSGBOX to examine the five values of pamRec(i).flag. The first one should
    have a value of 17. If I allign along a WORD boundary, everything is ok.
    And if I change the order of the elements, putting the flag element after the
    catg element, it is ok. Can anyone explain this behavior to me. I need to
    understand this to prevent future bugs in my code.

    Thanks for any help.


    Code:
    #COMPILE EXE
    #DIM ALL
    
    TYPE pamRecord 'WORD
      Lname AS BYTE
      Fname AS BYTE
      homePhone AS BYTE
      busPhone AS BYTE
      cellPhone AS BYTE
      faxPhone AS BYTE
      toTitle AS BYTE
      toName AS BYTE
      addr1 AS BYTE
      addr2 AS BYTE
      city AS INTEGER
      email AS BYTE
      catg AS BYTE
      'flag AS BYTE
      unused AS BYTE
      dataLength AS INTEGER
      zip AS LONG
      flag AS BYTE
    END TYPE
    
    FUNCTION PBMAIN()
       LOCAL i AS INTEGER, num AS INTEGER
       DIM pamRec(1:5) AS pamRecord
       DIM rec AS pamRecord
       num = 4
       pamRec(1).flag = 1
       pamRec(2).flag = 2
       pamRec(3).flag = 3
       pamRec(4).flag = 4
       rec.flag = 17
       INCR num
       ARRAY INSERT pamRec(1) FOR num, rec
       FOR i = 1 TO 5
          MSGBOX STR$(pamRec(i).flag)
       NEXT i
    END FUNCTION

  • #2
    Charles,

    There is small "inconvenience" in PB (I meet it in my programms). Last member of UDT in ARRAY INSERT is cleared. You must make additional assign after ARRAY INSERT statement.

    Regards

    Cezary

    ------------------

    Comment


    • #3
      Thanks guys, I've passed this along to PowerBASIC R&D to investigate.

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment

      Working...
      X