[Implemented] This would allow Procedures more versatile

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

[Implemented] This would allow Procedures more versatile

Post by Psychophanta »

Let me explain with this example:
I have this nice function:

Code: Select all

Procedure BezierCubicLine(PointList.f(2),res.f=0.02)
  Protected t0.f=0.0,t1.f=1.0,bx0.f=PointList(3,0),by0.f=PointList(3,1),bx.f,by.f
  t0.f+res:t1.f-res
  While t1.f>=0
    bx.f=PointList(0,0)*t0*t0*t0+3*PointList(1,0)*t1*t0*t0+3*PointList(2,0)*t1*t1*t0+PointList(3,0)*t1*t1*t1
    by.f=PointList(0,1)*t0*t0*t0+3*PointList(1,1)*t1*t0*t0+3*PointList(2,1)*t1*t1*t0+PointList(3,1)*t1*t1*t1
    LineXY(bx0,by0,bx,by)
    bx0.f=bx:by0.f=by
    t0.f+res:t1.f-res
  Wend
EndProcedure
As you can see, the function gets an array (PointList.f(2)) which is a table containing a total of 4 2D coordenates.
In order to call to that function this can be done:

Code: Select all

Dim Pointsl.f(3,1)
BezierCubicLine(Pointsl.f())
or also

Code: Select all

Dim Pointsl.f(3,1)
BezierCubicLine(@Pointsl.f())
.
The fact is that the array is passed by reference (and the same happens when passing a linked list), i.e. we are indeed passing a pointer.

Well, if i have the table in a DataSection (i.e. pointed by a label) or in general in a '*pointer' variable, then i can not use that function, but another like this:

Code: Select all

Procedure BezierCubicLine(*PointList.f,res.f=0.02)
, which does not allow the array passing.
Making possible the call with any kind of pointer (not just an array or linkedlist pointer), the function is much more versatile.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Code: Select all

Procedure BezierCubicLine(*PointList.float,res.f=0.02)
You can pass a one-dimensional array to this code.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Trond wrote:

Code: Select all

Procedure BezierCubicLine(*PointList.float,res.f=0.02)
You can pass a one-dimensional array to this code.
Yes, but can not handle it as an array inside the Structure, you see?
The point is to get a data stream and handle it as array (if wanted to work with a random access data stream), or as linked list (if wanted to work with a sequential access data stream).
I really think that it would be a good implementation.
Last edited by Psychophanta on Sat Feb 16, 2008 5:22 pm, edited 1 time in total.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Both arrays and linkedlists store extra information which is not available when you
pass a simple pointer.
Thats why this is not possible.
quidquid Latine dictum sit altum videtur
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Ohh! That's a pity,
i thought for a while there was a good reason why it was not already implemented.
Thank you for your clear explanation.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply