LikedList as Parameter

Just starting out? Need help? Post your questions and find answers here.
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

LikedList as Parameter

Post by Konne »

What am I doing wrong in this Code. (I'm trying to give a LisnkedList) to a procedure.

Code: Select all

Structure Request
  Image.s
EndStructure

ProcedureDLL Requester(*Request.Request())


    Debug AddElement(*Request())      
    Debug *Request()    
    
    CallFunctionFast(@Requester(),*Request())
    
    CallDebugger

EndProcedure


NewList Request.Request()
Requester(@Request())
Apart from that Mrs Lincoln, how was the show?
benny
Enthusiast
Enthusiast
Posts: 465
Joined: Fri Apr 25, 2003 7:44 pm
Location: end of www
Contact:

Post by benny »

@Konne:

I do not fully understand your source and what you intend to do with it :?:
You call the procedure Request recursively over and over again with
CallFunctionFast which will lead in a kind of zombie process.

Anyway if you want to call the procedure again in itself, I guess you would
have to pass a pointer on a pointer (**pRequest in C) as a parameter afaik - but
I am not quite sure if purebasic supports it and if I am right with this
statement :roll: .

Otherwise, you pass the linkedlist correctly imho:

Code: Select all

Structure Request
  Image.s
EndStructure

ProcedureDLL Requester(*Request.Request())


    Debug AddElement(*Request())     
    *Request()\Image = "Hello"
    
;    Debug *Request()   
   
    ;CallFunctionFast(@Requester(),*Request())
   
    ;CallDebugger

EndProcedure


NewList Request.Request()
Requester(@Request())
SelectElement(Request(), 0)
Debug Request()\Image
Nevertheless, I think it is now (PB V4.0) possible to simple pass a linked
list / array as a "normal" parameter:

See : http://freak.purearea.net/v4/ReadMe.html#arrayparam
regards,
benny!
-
pe0ple ar3 str4nge!!!
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Your over complicating things:

Code: Select all

NewList Numbers.l()

AddElement(Numbers())
Numbers() = 25

AddElement(Numbers())
Numbers() = 50

AddElement(Numbers())
Numbers() = 75

Procedure EchoList(MyList.l())
	ForEach MyList()
		Debug MyList()
	Next
EndProcedure

EchoList(Numbers())
--Kale

Image
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post by Konne »

i know all this stuff but my problem is I need the recursion. Letzt explain my situation:

I have a dll with the funktion Request() this funktion has a LL as parameter. Now I have to call a funtion from an other dll, also with the same LL as Parameter. How can I do this without Memory Errors.
Apart from that Mrs Lincoln, how was the show?
benny
Enthusiast
Enthusiast
Posts: 465
Joined: Fri Apr 25, 2003 7:44 pm
Location: end of www
Contact:

Post by benny »

@Konne:

As I said, I think passing a pointer as a parameter in a recursion would require
the usage of a pointer on a pointer (symbolized as '**' in C e.g.). At least
in your case. [Although I am not 100% sure about this point - so anyone feel
free to correct me if I am wrong ;-) ]

Anyway, as the posted link says, PB4.0 now allows you to pass Linked Lists
and arrays as parameters, so why not use it :?: Maybe I still don't get your
point :roll:

Code: Select all


Structure Request
  Image.s
EndStructure

Global t.l
t.l = 0

ProcedureDLL Requester(Request.Request())

    Shared t.l
    
    t + 1
    Debug "Turn: " + Str(t)
    
    AddElement(Request())
            
    If t < 10
      Requester(Request())
    EndIf    
    
    ;CallFunctionFast(@Requester(),Request())
   
    ;CallDebugger

EndProcedure


NewList Request.Request()
Requester(Request())
Debug Str(CountList(Request()))
regards,
benny!
-
pe0ple ar3 str4nge!!!
Post Reply