Menu

#731 redim not working on passed array

closed
nobody
redim (2)
compiler
2020-11-09
2014-06-02
c Rex
No

FreeBASIC Compiler - Version 0.90.1 (07-17-2013) for win32
dim as integer a(2)

sub temp(a() as integer)
redim a(3 to 4)
end sub

temp a()
? lbound(a), ubound(a)

Discussion

  • Matthew

    Matthew - 2014-06-02

    It's to do with a() being a fixed-size array. It's not allocated memory and can't be changed.
    It works if you make it dynamic though, e.g. dim a() or redim a(0 to 2).

    I don't know what the best behaviour for a fixed array would be. But from brief tests, what happens is that on redim new memory is allocated, overriding the fixed-size data, and is deallocated at the end of the sub (or at least, an array of objects will be constructed and destroyed).

    On redim preserve though, it seems to give an "out of memory" error. That would be a bug.

     
  • dkl

    dkl - 2014-06-02

    The compiler/runtime currently has no way to know whether the passed array is really dynamic or not. REDIM is only possible in case it's dynamic.

    How about adding a flag to the array descriptors which the compiler creates for fixed-size arrays, and letting REDIM trigger a runtime error when given a fixed-size array? ERASE could perhaps also use this to change behaviour accordingly.

     
  • Matthew

    Matthew - 2014-06-02

    I've just checked in QBasic, and code like this shows a "Duplicate definition" runtime error.
    A flag sounds like a good idea. But a corresponding method to test the "fixedness" of an array would be useful too.

     
  • Matthew

    Matthew - 2014-06-02

    Sorry, just found a related bug: in recent builds, keywords after REDIM [PRESERVE] - e.g. REDIM PRINT foo are causing a segfault.

     
  • dkl

    dkl - 2014-06-02

    This should fix the crash issue: [12f1e2]

     

    Related

    Commit: [12f1e2]

  • Jeff Marshall

    Jeff Marshall - 2020-10-24
     
  • Jeff Marshall

    Jeff Marshall - 2020-10-24

    Fixed in fbc 1.08 [91b9f4df11f21d2056316d3836ea4ea00323f71d]

    If compiled with '-e' option for run-time error checking, the REDIM will throw an error.

    If not compiled with '-e' then then REDIM silently fails and the array is not resized

     

    Related

    Commit: [91b9f4]

  • Jeff Marshall

    Jeff Marshall - 2020-11-09
    • status: open --> closed
     

Log in to post a comment.