Re: ... Operator
Posted: Mon Jun 22, 2020 9:20 am
Thank you. I missed that trick. The numbers had appeared random for all parameters. I thought that there was something behind the scenes that supplied the count and that it was somehow automatically placed there.Josh wrote:User_Russian passes the number of following parameters as the first parameter when calling the procedure Test() and the procedure evaluates this again. There is no miracle behind this.
I ran into a snag when testing User_Russian's code sample as written above without any modifications. The results are incorrect. This is what is displayed:
Code: Select all
Count = 2
Parameters: 0 0
----
Count = 10
Parameters: 140717973961617 0 8192000 100 4 1234 10000 10 16 80
----
I did change User_Russian's method here to use CallFunctionFast() instead of CallCFunctionFast(). Here is my test code I used:
Code: Select all
Structure ArrI
i.i[0]
EndStructure
Prototype MultiArgInteger(Count,a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,a7=0,a8=0,a9=0,a10=0,a11=0,a12=0,a13=0,a14=0,a15=0,a16=0,a17=0,a18=0,a19=0)
Procedure Test(Count)
Protected *Param.ArrI=@Count+SizeOf(Count)
Protected i
PrintN("Count = "+Count)
Print("Parameters: ")
For i=0 To Count-1
Print(Str(*Param\i[i])+" ")
Next
PrintN(#CRLF$+"----")
EndProcedure
Procedure max(Count)
Protected *Param.ArrI = @Count + SizeOf(Count)
Protected mx = *Param\i[0]
Protected i
For i = 0 To Count - 1
If *Param\i[i] > mx: mx = *Param\i[i]: EndIf
Next
ProcedureReturn mx
EndProcedure
Define Display.MultiArgInteger = @Test(), Max_multi.MultiArgInteger = @max()
OpenConsole()
CallFunctionFast(@Test(), 2, 1, 2)
CallFunctionFast(@Test(), 10, 2, 8, 20, 100, 4, 1234, 10000, 10, 16, 80)
Display(2, 1, 2)
Display(10, 2, 8, 20, 100, 4, 1234, 10000, 10, 16, 80)
PrintN("max value:" + Max_multi(3,22,133,45)) ; result --> 133
PrintN("max value:" + Max_multi(6,90,88,12,45,677,211)) ; result --> 677
PrintN("max value:" + Max_multi(8,33,25,233,85,11,231,34,64)) ; result --> 233
Input()
Code: Select all
Count = 2
Parameters: 0 0
----
Count = 10
Parameters: 5368715837 34 0 100 4 1234 10000 10 16 80
----
Count = 2
Parameters: 1 2
----
Count = 10
Parameters: 2 8 20 100 4 1234 10000 10 16 80
----
max value:133
max value:677
max value:233
Code: Select all
Count = 2
Parameters: 0 0
----
Count = 10
Parameters: 140717973961617 0 8323072 100 4 1234 10000 10 16 80
----
Count = 2
Parameters: 10000 10
----
Count = 10
Parameters: 10000 10 16 100 4 1234 10000 10 16 80
----
max value:5368713718
max value:140717973961617
max value:140717973961617