Code: Select all
procedure ABC( a,b,c.s="")
it'd be nice to have a function to tell how many parameters were, indeed, passed.
Code: Select all
procedure ABC( a,b,c.s="")
Code: Select all
Procedure Test(A.i, B.i=2, C.i=3)
EndProcedure
Test(1)
Code: Select all
; Procedure Test(A.i, B.i=2, C.i=3)
_Procedure0:
MOV qword [rsp+8],rcx
MOV qword [rsp+16],rdx
MOV qword [rsp+24],r8
Code: Select all
; Test(1)
MOV r8,qword 3
MOV rdx,qword 2
MOV rcx,qword 1
CALL _Procedure0
Code: Select all
Procedure Test(a, b=-1, c=1, d=0)
If b = Default
b=-1
EndIf
If c = Default
c=1
EndIf
If d = Default
d=0
EndIf
...
Debug Test(45, Default, 15)
Code: Select all
Structure ArrI
i.i[0]
EndStructure
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
ProcedureC Test(Count)
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
ProcedureC Test(Count, x, y, z)
CompilerElse
CompilerError "Not supported"
CompilerEndIf
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
OpenConsole()
CallCFunctionFast(@Test(), 2, 1, 2)
CallCFunctionFast(@Test(), 10, 2, 8, 20, 100, 4, 1234, 10000, 10, 16, 80)
Input()
Code: Select all
#Default = -9999
Procedure.s Test(a, b=-1, c=1, d=0)
dv.s = "Defaults: "
If b = #Default
b=-1
dv + " b "
EndIf
If c = #Default
c=1
dv + " c "
EndIf
If d = #Default
d=0
dv + " d "
EndIf
If Len(dv) = 10 : dv ="" : EndIf
ProcedureReturn dv
EndProcedure
Debug Test(45, #Default, 15)
Debug Test(45, 10, 1)
Debug Test(45, 4, 15, 0)
Debug Test(45, #Default, #Default, #Default)
Wow!, I like this. This I am saving as a snipit for the future. Thank you for sharing this.User_Russian wrote: Sat Apr 29, 2023 12:42 pm viewtopic.php?p=553643#p553643Code: Select all
Structure ArrI i.i[0] EndStructure CompilerIf #PB_Compiler_Processor = #PB_Processor_x86 ProcedureC Test(Count) CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64 ProcedureC Test(Count, x, y, z) CompilerElse CompilerError "Not supported" CompilerEndIf 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 OpenConsole() CallCFunctionFast(@Test(), 2, 1, 2) CallCFunctionFast(@Test(), 10, 2, 8, 20, 100, 4, 1234, 10000, 10, 16, 80) Input()
Code: Select all
CallCFunctionFast(@Test(), 2, 1, 2)
CallCFunctionFast(@Test(), 10, 2, 8, 20, 100, 4, 1234, 10000, 10, 16, 80)
Linux x64 6.01 C Opt:
Count = 2
Parameters: 2 1
----
Count = 10
Parameters: 139691493705216 1 140723430533024 -179862365584584960 140723430533480 0 4211280 4367686 1234 10000
----
Linux x64 C
Count = 2
Parameters: 0 140724837002400
----
Count = 10
Parameters: 0 140724837002304 0 14170240 0 0 0 0 14170240 0
----
Linux x64 ASM
Count = 2
Parameters: 1 2
----
Count = 10
Parameters: 2 8 20 140734790934816 4 139982607847488 1 4372198 1234 10000
----