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 Professional Discussion / Passing arrays to/from functions: How to?

Author
Message
Talonos
16
Years of Service
User Offline
Joined: 11th Jun 2010
Location:
Posted: 28th Jul 2010 15:30
I wish to pass a variable length array (called a list in this language?) into a function, and have it return a fixed length array back to the calling function. I'm having a hard time figuring out how to do it, or if the capability exists. Is there somebody here who could enlighten me? I've tried several ways, but been unable to get it to work.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 28th Jul 2010 16:50
I've not found a way to do that EXCEPT to make the arrays global.

The fastest code is the code never written.
Talonos
16
Years of Service
User Offline
Joined: 11th Jun 2010
Location:
Posted: 28th Jul 2010 18:41
Hurmm.... I dislike Kludgey solutions, but I guess I'll have to go with globals, then. Thank you for confirming my fears.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Jul 2010 21:22
It is possible to pass arrays into and out of functions, but I'm afraid it's still kludgey.

With my array plug-in (part of my plug-in set), you can get pointers to array contents, and you can separate the pointer from the array and vice versa.

Here's an example that passes an array of integers containing the squares of 0 to 10 into a function, updates that arrays content within the function, and then adds a few more entries to the array. It then passes back the results:


Bottom line - it's not nice to use, you have to get all steps right or else it'll crash, and personally, I don't use it very much at all.

But it's there if you want to use it.

BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 29th Jul 2010 06:09 Edited at: 29th Jul 2010 06:12
arrays are global by default, just create them at the beginning of your program and use them in any subroutine or function
You can pass the current length of the array to the function if you want to

Login to post a reply

Server time is: 2026-07-25 21:25:39
Your offset time is: 2026-07-25 21:25:39