When we create a dynamic array of UDT with only a destructor (without implicit or explicit constructor), the first element(s) or more of the array is(are) badly initialized (relating their member data values per default)!
Example:
Type UDT I As Integer Declare destructor () End Type Destructor UDT () End Destructor Dim u1(3 to 7) As UDT Print u1(3).I, u1(4).I, u1(5).I, u1(6).I, u1(7).I Dim N As Integer = 7 Dim u2(3 to N) As UDT Print u2(3).I, u2(4).I, u2(5).I, u2(6).I, u2(7).I Redim u3(3 to N) As UDT Print u3(3).I, u3(4).I, u3(5).I, u3(6).I, u3(7).I Dim pu As UDT Ptr = New UDT[5] Print pu[0].I, pu[1].I, pu[2].I, pu[3].I, pu[4].I Sleep
Result:
0 0 0 0 0 3342792 3342792 1129469263 1346196293 1767332922 3342760 3342760 1180130387 1378775925 1996510021 0 0 0 0 0
If we suppress the destructor, or if we add a constructor (implicitly by an initializer, or by including an object with constructor, or even with an explicit empty constructor), the fault disappears!
This bug is already present from fbc version 0.17 (the first version which supports UDT destructor).
From fbc version 0.18.2 up to fbc version 0.20.0, this even induces an "Aborting due to runtime error 12 ("segmentation violation" signal)" from the compiler.
The example works properly here with git HEAD on linux.
Fixed by [7ec04a]
The simple example showed only zeroes for me aswell, but valgrind reported the accesses to uninitialized memory.
Related
Commit: [7ec04a]