hello,
how do i pass an array as a function argument in purebasic?
seems a dumb question, i know (:-)
pieter
how do i pass an array as a function argument in purebasic?
One way is to pass the address of the array.
Note that we are effectively passing by reference here.
Code: Select all
#NoElements = 10
Procedure testarray(AddressOfArray.l)
Dim TempArray.s(0)
TempArray() = AddressOfArray
Debug TempArray(1)
TempArray(1) = "Goodbye!"
EndProcedure
Dim a.s(#NoElements)
a(1) = "Hello!"
testarray(a()); NOTE that a() gives the address of the array a.
Debug a(1)
End
I may look like a mule, but I'm not a complete ass.
how do i pass an array as a function argument in purebasic?
Thanks srod,
I will give it a try, even though it still seems a little bit odd to me. Probably because I excpect behaviour simillar to other programming languages.
Cheers,
Pieter Greyling
I will give it a try, even though it still seems a little bit odd to me. Probably because I excpect behaviour simillar to other programming languages.
Cheers,
Pieter Greyling
[-pg-]
Ok, how would I be able to redim the TempArray with a new size after it is mapped to the AddressofArray? Especially if I do the following:
It will erase it's map to the AddressofArray..
I need to be able to resize the array the pointer is pointing to whenever I need to, within this routine, via pointer.
Code: Select all
Dim TempArray.s(25)
I need to be able to resize the array the pointer is pointing to whenever I need to, within this routine, via pointer.