'set up some values
Dim as Integer n=200000
Dim Shared arr2(1 to n) as WString*50
Sub combsort( arr1() As WString*50,begin As integer,finish As Integer)
Dim size As Integer=(finish)
Dim switch As Integer=0
Dim j As Integer=0
Dim As Single void=size
Dim aux As WString*50
Do
void=void/1.3: If void<1 Then void=1
switch=0
For i As Integer =begin To size-void
j=i+void
If arr1(i)>arr1(j) Then
aux= arr1(i)
arr1(i)=arr1(j)
arr1(j)=aux
switch=1
End If
Next
Loop Until switch =0 And void=1
End Sub
'example
Randomize
for i as Integer=1 to n
arr1(i)= "element " + Str(CInt(rnd*100))
Next
combsort(arr2(),1,UBound(arr2))
sleep
'set up some values
Dim as Integer n=200000
Dim Shared arr2(1 to n) as WString * 50
#macro combsort( arr1,begin,finish)
#print typeof(arr1)
scope
Dim size As Integer=(finish)
Dim switch As Integer=0
Dim j As Integer=0
Dim As Single void=size
Dim aux As typeof(arr1)' i.e. WString * 50
Do
void=void/1.3: If void<1 Then void=1
switch=0
For i As Integer =begin To size-void
j=i+void
If arr1(i)>arr1(j) Then
aux= arr1(i)
arr1(i)=arr1(j)
arr1(j)=aux
switch=1
End If
Next
Loop Until switch =0 And void=1
end scope
#endmacro
'example
Randomize
for i as Integer=1 to n
arr2 (i)= "element " + Str(CInt(rnd*1000000))
Next
combsort(arr2,1,UBound(arr2))
for i as Integer=1 to 50
print i, arr2 (i)
Next
sleep
Your code, but slightly modified only, by using an improved UDT defining an overloaded Cast and Let operator:
('arr(i).w' can be shortcut by the 'arr(i)' usage which then calls the Cast or Let operator, but at some expense of execution speed)
Type WString50
Dim As WString*50 w
Declare Operator Cast () Byref As WString
Declare Operator Let (Byref w0 As WString)
End Type
Operator WString50.Cast () Byref As WString
Return This.w
End Operator
Operator WString50.Let (Byref w0 As WString)
This.w = w0
End Operator
'set up some values
Dim as Integer n=200000
Dim Shared arr2(1 to n) as WString50
Sub combsort( arr1() As WString50,byval begin As integer,byval finish As Integer)
Dim size As Integer=(finish)
Dim switch As Integer=0
Dim j As Integer=0
Dim As Single void=size
Dim aux As WString*50
Do
void=void/1.3: If void<1 Then void=1
switch=0
For i As Integer =begin To size-void
j=i+void
If arr1(i)>arr1(j) Then
aux= arr1(i)
arr1(i)=arr1(j)
arr1(j)=aux
switch=1
End If
Next
Loop Until switch =0 And void=1
End Sub
'example
Randomize
for i as Integer=1 to n
arr2(i)= "element " + Str(CInt(rnd*100))
Next
combsort(arr2(),1,UBound(arr2))
sleep
Pull request #158 solves the problem of z/wstring arrays passed as parameter not working properly. This is because the size of z/wstrings passed as parameter is lost. For z/wstring arrays the size of an element is stored in the array descriptor too. I added RtlCalcStrLen2, which accounts for this by using the size held in the descriptor for bydesc parameters.
For "regular" z/wstring parameters access and assignment works, but it is possible to cause overflow for such parameters