Is it possible to allow for Mercury to allow static arrays inside of structures?
That should be fine already? Can you give me an example that fails or does not work as you’d expect?
thanx,
marc
At the moment I currently do not have Mercury installed so it’s more of an assumption. I’m going off VB.NET’s original functionality where only dynamic arrays were allowed in structs. Does the following example work?:
Structure Vec3
Dim x,y,z As Double
End Structure
Structure Face
Dim points(3) As Vec3
End Structure
Compiles w/o errors for me.
Okay great. I edited the original post for clarification.
I’ve tested the code out myself and when obtaining the structure size it seems that even a static array passes a pointer instead of the entire block as expected. This can cause issues when using structs with static arrays (either to other value types or structs) to external API’s. This is intended for use with the Island backend.
Module Program
Structure test
Dim x,y,z As Double
End Structure
<Packed>
Structure test2
Dim v(2) As test
Dim t As Byte
End Structure
Sub Main(args as String())
Dim t As test2
writeLn("Size: " + sizeOf(test2)) 'Returns 9 instead of expected 25
End Sub
End Module
Hmm. Let me see. unsized/dynamic arrays should be started as pointers, but fixed0size arrays should be inline in there containing type (or on the stack)…
see Array Types form details
Curious, but reproduced. in Mercury i get
Size: 24 // test
Size: 9 // test2
while in Oxygene I get
Size: 24 // test
Size: 49 // test2
as expected. will log.
Logged as bugs://E26714.
Reading the array types article also made me want to test multidimensional arrays. It seems it cannot be assigned in Mercury to structs for some reason:
Module Program
Structure test
Dim x,y,z As Double
End Structure
Structure test2
Dim v(2) As Byte
Dim t As Byte
End Structure
Sub Main(args as String())
Dim t(2,2) As test
writeLn("Size: " + sizeOf(t))
End Sub
End Module
This throws the following error: (E62) Type mismatch, cannot assign “array of array of Program.test” to “array[0…3, 0…3] of Program.test”
EDIT: This also happens with standard value types (ie…Dim t(2,2) As Byte). It seems multidimension arrays are broken altogether.
Very strange, but reproduced. definitely a bug.
Logged as bugs://E26715.
also, this should be a 2x2 array, not a 4x4 array, right?
Technically it would be a 3x3 2D matrix due to the zero indexing (0 [1], 1 [2], 2 [3]).
Ah ok. so for Integer(x)
, x is not the size of the array but the top index? i do recall that this was strange back when we implemented Mercury, but I didn’t remember which way it was strange. 0…3 is wring either way
Yes, in VB.NET you would define the top index as it’s not indexed starting at 1 as in older versions of BASIC.
Also, I understand that the Cooper backend currently doesn’t support multidimensional arrays. Was this due to the feature not being implemented, or a technical reason?
Platform limitation, I believe. @ck?
bugs://E26714 was closed as fixed.
Issues should be fixed now.
Sized arrays are allowed in structures.
Fixed declaring multidim arrays, size and Type mismatch issue.