Page 1 of 1
how do i pass an array as a function argument in purebasic?
Posted: Wed Jul 21, 2004 9:43 pm
by pieter
hello,
how do i pass an array as a function argument in purebasic?
seems a dumb question, i know (:-)
pieter
Posted: Wed Jul 21, 2004 10:00 pm
by srod
One way is to pass the address of the array.
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
Note that we are effectively passing by reference here.
how do i pass an array as a function argument in purebasic?
Posted: Thu Jul 22, 2004 5:40 pm
by pieter
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
Posted: Sun Sep 05, 2004 7:46 pm
by Shannara
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.