Announcement

Collapse
No announcement yet.

ARRAY INSERT bug?

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

  • Tom Hanlin
    replied
    The alignment refers to the members of the TYPE, e.g., WORD alignment
    will cause each member of the UDT to be word-aligned. This is typical
    behavior for every compiler I've seen that supports custom alignment.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Leave a comment:


  • Guest
    Guest replied
    Lance, doesn't byte alignment only pad the total length of a structure/UDT to
    a size evenly divisible by the size of the alignment data type?

    For instance, in your example:
    [code]
    TYPE MyData DWORD
    V1 AS INTEGER
    V2 AS INTEGER
    V3 AS INTEGER
    V4 AS INTEGER
    V5 AS STRING * 5
    END TYPE
    ... I would have expected the length of the structure to be padded to 16 bytes
    instead of each variable in the structure being padded to a DWORD boundary.

    Why is the structure length padded to 24 bytes instead of 16 bytes? Is each variable in
    the structure padded to DWORD alignment instead of the structure
    being padded to a DWORD alignment size?

    Leave a comment:


  • Lance Edmonds
    replied
    If the problem is actually evident, the very last byte (and only the last byte) of the inserted UDT structure may be affected.

    Therefore, simply adding a dummy byte to pad the structure, or using any alignment that effectively pads the UDT to provide an additional byte should be a sufficient workaround.

    Remember, the total byte count of a UDT is affected by the alignment method specified. For example, if DWORD is used, then the UDT will be a multiple of 4 bytes in length, etc.

    Therefore, a structure such as...
    Code:
    TYPE MyData DWORD
      V1 AS INTEGER
      V2 AS INTEGER
      V3 AS INTEGER
      V4 AS INTEGER
      V5 AS STRING * 5
    END TYPE
    ...will be 24 bytes in length.




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

    Leave a comment:


  • Eric Pearson
    replied
    Ron --

    It seems to. I tried WORD and DWORD alignment and Bern's problem disappeared.

    But remember, I am just guessing (at this point) that alignment is the root of the problem. It could be that we are just masking the real problem, and that a different structure will behave differently. Until we get a confirmation from PB, I would not consider this to be a reliable workaround.

    -- Eric

    ------------------
    Perfect Sync Development Tools
    Perfect Sync Web Site
    Contact Us: mailto:[email protected][email protected]</A>

    Leave a comment:


  • Guest
    Guest replied
    Does the TYPE "alignment" parameter also fix the problem by automagically
    padding the structure as necessary to achieve the specified alignment.

    Code:
    TYPE My_UDT
      F2       AS WORD
      F3       AS WORD
      F4       AS BYTE
    END TYPE  '  Might have problem ???
     
    TYPE My_UDT DWORD
      F2       AS WORD
      F3       AS WORD
      F4       AS BYTE
    END TYPE  '  WILL NOT have problem ???
    [This message has been edited by Ron Pierce (edited March 05, 2001).]

    Leave a comment:


  • Eric Pearson
    replied
    Bern --

    You can also add an extra byte to your structure (like F23 AS BYTE) to work around the problem. I'm not sure, but it looks to me like "data alignment" is involved.

    BTW, even after the compiler glitch is fixed, there are some good reasons to keep your structures WORD aligned or, better yet, DWORD aligned. 32-bit processors can perform their tasks more efficiently when data is aligned on 32-bit boundaries. The CPU actually has to perform extra steps to access 1- and 2- byte numeric values. That's why LONG variables are the fastest numeric type, with DWORD a close second.

    -- Eric


    ------------------
    Perfect Sync Development Tools
    Perfect Sync Web Site
    Contact Us: mailto:[email protected][email protected]</A>

    Leave a comment:


  • Lance Edmonds
    replied
    Thanks, however, this one has been reported here before. R&D assure me that it will definitely be corrected in the next update to the compiler.

    To be clear, the bug is described thus "ARRAY INSERT may clear the last byte of an inserted user defined type under certain conditions".

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

    Leave a comment:


  • Bern Ertl
    started a topic ARRAY INSERT bug?

    ARRAY INSERT bug?

    The following works correctly if you change F20-F22 to WORDS.
    But it does not work correctly as is......

    Code:
    #COMPILE EXE
    #REGISTER NONE
    #DIM ALL
    
    
    TYPE Ten_Quad
       TQ(10) AS QUAD
    END TYPE
    
    
    TYPE My_UDT
       F1       AS STRING * 80
       F2       AS WORD
       F3       AS WORD
       F4       AS WORD
       F5       AS WORD
       F6       AS WORD
       F7       AS QUAD
       F8       AS DWORD
       F9       AS Ten_Quad
       F10      AS DWORD
       F11      AS DWORD
       F12      AS DWORD
       F13      AS DWORD
       F14      AS DWORD
       F15      AS DWORD
       F16      AS DWORD
       F17      AS DWORD
       F18      AS DWORD
       F19      AS WORD
       F20      AS BYTE
       F21      AS BYTE
       F22      AS BYTE
    END TYPE
    
    
    %MYEQUATE    = 202
    
    
    FUNCTION PBMAIN () AS LONG
    
    
       LOCAL SBuff AS My_UDT
    
    
       DIM ABuff( 1: 10) AS My_UDT
    
    
       SBuff.F1 = "THIS IS INSERTED"
       SBuff.F2 = 8
       SBuff.F19 = 8
       SBuff.F20 = 8
       SBuff.F21 = 8
       SBuff.F22 = %MYEQUATE
    
    
       ARRAY INSERT ABuff( 4), SBuff
    
    
       MSGBOX "ABuff(4).F1 ="+RTRIM$(ABuff( 4).F1)+ $TAB + "SBuff.F1 ="+RTRIM$(SBuff.F1) + $CRLF + _
              "ABuff(4).F2 ="+STR$(ABuff( 4).F2)+ $TAB + "SBuff.F2 ="+STR$(SBuff.F2) + $CRLF + _
              "ABuff(4).F19 ="+STR$(ABuff( 4).F19)+ $TAB + "SBuff.F19 ="+STR$(SBuff.F19) + $CRLF + _
              "ABuff(4).F20 ="+STR$(ABuff( 4).F20)+ $TAB + "SBuff.F20 ="+STR$(SBuff.F20) + $CRLF + _
              "ABuff(4).F21 ="+STR$(ABuff( 4).F21)+ $TAB + "SBuff.F21 ="+STR$(SBuff.F21) + $CRLF + _
              "ABuff(4).F22 ="+STR$(ABuff( 4).F22)+ $TAB + "SBuff.F22 ="+STR$(SBuff.F22)
    
    
    END FUNCTION
    ------------------
    Bernard Ertl
Working...
X