Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / How to pass an array to a function?

Author
Message
Fud
20
Years of Service
User Offline
Joined: 16th Nov 2004
Location:
Posted: 17th Jan 2007 23:56
How does one pass an array to a function in DB? When I try `function name(array(10))` I get an error.

Thanks in advance!
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 17th Jan 2007 23:57 Edited at: 11th Aug 2010 20:08
It's not supported in either DB or DBPRO.

Fud
20
Years of Service
User Offline
Joined: 16th Nov 2004
Location:
Posted: 18th Jan 2007 00:24
Oh noes!
Thanks for your quick reply, I'll have to work around this limitation.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 18th Jan 2007 14:18
Quote: "I'll have to work around this limitation"


No need!

When you arrive at the function, you can access the array as though you had passed it. (Arrays are global in DB when declared in the main program).

TDK_Man

Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 18th Jan 2007 23:17
TDK, that can be a good thing and a bad thing.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 18th Jan 2007 23:45
I didn't say it was good... or bad!

I just said it was possible.

TDK_Man

Uncle Sam
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 23rd Jan 2007 21:41 Edited at: 23rd Jan 2007 21:42
Yeah, he, uh, didn't.

Quote: "function name(array(10))"


I don't see why that wouldn't work, I've done that innumerable times.

Uncle Sam
Nvidia Geforce 7950GT 512MB PCIEx, 2.66 GHZ Pentium 4 proccessor, 1GB RAM
Need particles? Click here!
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 24th Jan 2007 12:09 Edited at: 11th Aug 2010 20:09
The original poster is referring to passing the entire array into the function by reference/pointer (whatever floats your boat), rather than individual elements from the array. This allows you to build generic functions that can perform operations on whatever array() you pass into them.

i.e (PB example)




You can simulate the same type of behavior in standard DB using caches (ranges) in a global arrays (see example #2), or mem blocks



Login to post a reply

Server time is: 2025-05-27 04:18:54
Your offset time is: 2025-05-27 04:18:54