But the procedure code does not work because the (Z|W)string size is not passed, and a size of 1 character is taken instead by default.
- Bug example:
Code: Select all
Sub test(z() As Zstring * 10)
For i As Integer = Lbound(z) To Ubound(z)
Print z(i)
Next I
End Sub
Dim As Zstring * 10 z(...) = {"one", "two", "three"}
test(z())
Sleep
- Conversely, passing a 'String * N' array to a procedure raises an error.
Code: Select all
one ne e
Passing a '[Z|W]string' array also raises an error.
- If everything worked fine, the compiler should also pass the zstring size to the procedure and do internally what I added in a macro:
Code: Select all
Sub test(z() As Zstring * 10, Byval size As Integer)
#define _z(n) *(@z(Ubound(z)) - Ubound(z) + (n) * size)
For i As Integer = Lbound(z) To Ubound(z)
' Print z(i)
Print _z(i)
Next I
End Sub
Dim As Zstring * 10 z(...) = {"one", "two", "three"}
test(z(), Sizeof(z(Lbound(z))))
print
Sleep
Code: Select all
one two three
- A workaround might be to pass an array of zstring pointers:
Code: Select all
Sub test(pz() As Zstring Ptr)
For i As Integer = Lbound(pz) To Ubound(pz)
Print *pz(i)
Next I
End Sub
Dim As Zstring Ptr pz(...) = {@"one", @"two", @"three"}
test(pz())
Sleep
Code: Select all
one two three
- Another workaround might be to define your zstring into a Type and then pass an array of Type elements:
Code: Select all
Type myZstring
z As zstring * 10
End type
Sub test(mz() As myZstring)
For i As Integer = Lbound(mz) To Ubound(mz)
Print mz(i).z
Next I
End Sub
Dim As myZstring mz(...) = {Type("one"), Type("two"), Type("three")}
test(mz())
Sleep
Code: Select all
one two three