Procedure - Integer arguments stored in a local array

Share your advanced PureBasic knowledge/code with the community.
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Procedure - Integer arguments stored in a local array

Post by Olli »

From the idea of FlatEarth :

; '____' 4 characters code to store the arguments of a procedure in a local array.

; array name is Arg()
; be careful to ArgCount which has been defined as a local integer

; -9223372036854775808 for X64
; 2147483648 for X86
; this is a reserved argument value

; only for integers and pointors
; 16 arguments maximum : you can expand this availability. Please request if needed.

; Good luck !

Code: Select all

;*************************************************************************************
; from the idea of FlatEarth
; 
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
   #None = 1 << 31
CompilerElse
   #None = 1 << 63
CompilerEndIf

Macro Ar_
 Argument# MacroExpandedCount = #None
EndMacro

Macro ____
 Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_, Ar_)
 Protected ArgCount.I
 For ArgCount = 0 To 15
  If PeekI(@Argument1 + ArgCount * SizeOf(Integer) ) = #None
   Break
  EndIf
 Next
 Dim Arg.I(ArgCount)
 Arg(0) = ArgCount
 For ArgCount = 1 To Arg(0)
  Arg(ArgCount) = PeekI(@Argument1 + (ArgCount - 1) * SizeOf(Integer) )
 Next
 ArgCount ! (0
EndMacro


;- Syntax example



Procedure Test(____)
 For I = 1 To Arg(0)
  Debug Arg(I)
 Next
EndProcedure

Test(1,2,5,10,20) ; <--- add up to 16 arguments
Last edited by Olli on Tue Jun 09, 2020 1:27 pm, edited 3 times in total.
FlatEarth

Re: Procedure - Integer arguments stored in a local array

Post by FlatEarth »

Hi, I'm very happy :D thank you for your efforts.

Why does this error appear when running?

[21:50:08] [COMPILER] Line 30: A ')' is expected to close the procedure.

Thanks again :wink:
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: Procedure - Integer arguments stored in a local array

Post by Olli »

:D I copied the code manually, doing this little mistake !

Normally, it should be better, now. I will add a little comment for X86s owners...

Thank you for having tested ! And I hope it will be useful. If you have any questions, I will try to answer rightly !


Regards
Mesa
Enthusiast
Enthusiast
Posts: 349
Joined: Fri Feb 24, 2012 10:19 am

Re: Procedure - Integer arguments stored in a local array

Post by Mesa »

Multi processor...

Code: Select all

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
  #None = 1 << 31 
CompilerElse
  #None = 1 << 63  
CompilerEndIf
M.
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: Procedure - Integer arguments stored in a local array

Post by Olli »

Hello mesa, thanks for you read and your suggest. I had 3 choices for this hardware difference :

Code: Select all

[ ] #Pb_Compiler_Processor
[ ] SizeOf(Integer)
[ ] Stay lazy
Naturally, I stayed lazy ! The coder must already add manually argument maximum, if its program passed over. If I add toomany complex lines, it can cause some troubles (in the brain, but not in the hardware ! )

Here is the SizeOf(Integer) version :

Code: Select all

#None = 1 << (SizeOf(Integer) - 1)
But your advise is more explicit : I insert yours.
Post Reply