Dynamic parameterstack

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
mk-soft
Always Here
Always Here
Posts: 6207
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Dynamic parameterstack

Post 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:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Dynamic parameterstack

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6207
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Dynamic parameterstack

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: Dynamic parameterstack

Post by Foz »

forgive my foolish musings, but why not pass in an array?
User avatar
mk-soft
Always Here
Always Here
Posts: 6207
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Dynamic parameterstack

Post by mk-soft »

I know, but this way is better for function "Format(...) " like sprintf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply