Page 1 of 1

Dynamic parameterstack

Posted: Fri Jan 22, 2010 9:55 am
by mk-soft
Dynamic parameter stack such as C.
Behind the last parameter still another zero parameter add over in the Procedure the latter to recognize.

Code: Select all

Procedure MyFunction( Para1.i, *Args ... ) ; *Args ; Pointer to parameterstack
  *value  = PeekI(*args) ; get pointer to value
  While *value
    ; ...
    *args + SizeOf(Integer) ; next parameter
    *value  = PeekI(*args) ; get pointer to value
  Wend
EndProcedure
GT :wink:

Re: Dynamic parameterstack

Posted: Fri Jan 22, 2010 10:05 am
by Fred
Unfortunately, this 'feature' from C is a tricky one and often leads to wierd crashs, especially because the parameter you pass are not typed (you can pass anything from float to quad, string etc.). We won't do this for PB, you can use default assignement if you need variable arguments.

Re: Dynamic parameterstack

Posted: Fri Jan 22, 2010 10:12 am
by mk-soft
I use these ready. All parameters however always land on the stack. This wanted only thereby an optimizing.

http://www.purebasic.fr/english/viewtop ... 12&t=32026

Thanks

Re: Dynamic parameterstack

Posted: Fri Jan 22, 2010 10:50 am
by Foz
forgive my foolish musings, but why not pass in an array?

Re: Dynamic parameterstack

Posted: Fri Jan 22, 2010 11:29 am
by mk-soft
I know, but this way is better for function "Format(...) " like sprintf