Menu ▾ ▴

#867 Fixed length strings array as type member

open
nobody
None
compiler
2017-10-18
2017-10-15
No

Fixed length string arrays as Type members do not maintain defined length. They also do not report correct length when using the Len() function.

Discussion

  • fxm (freebasic.net)

    Yes, something was missed when the feature of member dynamic arrays in a Type was added to FreeBASIC, for the particular case of fixed-length string dynamic array: their type seems non-completely defined by the compiler:

    No problem for a fixed-length static array in a Type.

    Highlighting example:

    Type mytype
       as string * 9 s1(2)
       as string * 9 s2(any)
    End type
    
    Dim As mytype m
    #print typeof(m.s1(1))
    #print typeof(m.s2(1))
    

    Compiler results:

    STRING * 9
    STRING * -1

    Therefore all keywords using the length of such a string are failing (LEN for example).

    For more details, see sancho3's topic "Problem with len()":
    https://www.freebasic.net/forum/viewtopic.php?f=3&t=26023

     

    Last edit: fxm (freebasic.net) 2017-10-16
  • dkl

    dkl - 2017-10-16

    I guess this is related to [#650] or at least the issue mentioned in the comments there:
    https://www.freebasic.net/forum/viewtopic.php?f=3&t=21188

     

    Related

    Bugs: #650

  • fxm (freebasic.net)

    This bug for a fixed-length string dynamic array affects only a non-static member using it. That works right for a static member and a non member:

    Dim As String * 9 s0(Any)
    Redim s0(2)
    
    s0(1) = "FreeBASIC"
    
    Type mytype
       Static As String * 9 s1(Any)
       Dim As String * 9 s2(Any)
    End type
    Redim mytype.s1(2)
    Dim As mytype m
    Redim m.s2(2)
    
    m.s1(1) = "FreeBASIC"
    m.s2(1) = "FreeBASIC"
    
    #print typeof(s0(1))
    #print typeof(m.s1(1))
    #print typeof(m.s2(1))
    
    Print s0(1), Len(s0(1))
    Print m.s1(1), Len(m.s1(1))
    Print m.s2(1), Len(m.s2(1))
    
    Sleep
    

    Compiler output:

    STRING * 9
    STRING * 9
    STRING * -1

    Program output:

    FreeBASIC      9
    FreeBASIC      9
    FreeBASIC     -1
    
     

    Last edit: fxm (freebasic.net) 2017-10-18

Log in to post a comment.