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 / Types in Functions??

Author
Message
pat1926
23
Years of Service
User Offline
Joined: 8th Jul 2003
Location:
Posted: 10th Jul 2003 10:17 Edited at: 10th Jul 2003 10:18
First, I know thats not how you multiply vectors this is just an example.

That being said, i would like to know why when i try to run that function with a type i get an error. Is it possible to have a funciton with types as the inputs? Could someone Please clarify this for me.

Sorry didnt mean to double post. Dont know what happened.

Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 10th Jul 2003 10:27
no it isn't... and we've not been told if it'll be added in the future either

Philip
23
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 10th Jul 2003 19:21
Might it be that you are trying to define a type with a name which is a reserved word? I think vector is a reserved word, right?

Its like defining a type as called "type" or "print", right?

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
pat1926
23
Years of Service
User Offline
Joined: 8th Jul 2003
Location:
Posted: 10th Jul 2003 19:27 Edited at: 10th Jul 2003 19:32
No that vector thing was just an example, i am using a different word in my program

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Jul 2003 22:14
Vector isn't a reserved word anyway...

But no, you can't pass types directly into functions.
Shadowfax
23
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 11th Jul 2003 02:13
Hi Pat

It is possible to
[1] (externally to the function) use make memory to aquire a block of memory of sufficient size

[2] write your data from your data type into the memory block

[3] pass the pointer to the memory block into the function as an integer

[4] (*VERY IMPORTANT*) cast the integer back into a pointer

[5] access the data from the memory block inside the function


...however
(1) firstly its a pain in the arse
(2) secondly you would really have to structure the code so most of your functions (to do this task) opperate in this manner and
(3) if your are not *extremely* careful, you can mistake a value for a pointer or vice versa and your code crashes to hell and back


Its not passing a data type but its as close as i have figured to get

"No Gir ... thats BAD !"
Shadowfax
23
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 11th Jul 2003 02:16
PS Anyone official will probably say you would be nuts to consider what i described but it does work for me



"No Gir ... thats BAD !"
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Jul 2003 02:45
I'm no official, but you're nuts ...

It's probably easier to use a global array (as they can be expanded on the fly) and pass the index as the parameter.

(1) Firstly, it's easy
(2) secondly, it's easy
(3) thirdly, it's easy

No crashes, no memory leaks (DBPro handles the memory allocations), and you get to use structures (types) instead of offsets in memory.



If you wanted to get clever, you could record which items were in use (via another array) so that you could free and reallocate items in the array.
swdave
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United States
Posted: 11th Jul 2003 04:42
It seems to be a BASIC feature that doesnt work. You can hard code your functions to use globals like so. Maybe the feature will get fixed and it will be easy to recode.



You could also use array/stack feature like IanM's example.

This example uses strings but types will work also. It's very simular to how any compiler passes parameters to a function (Push Data on Stack, Call function, Pop data off Stack). It will also allow you to create functions with variable number of parameters.



Dave...

indi
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 11th Jul 2003 08:06
the above snippet was missing the global statement for it to work




you can use an array as well, a typed array definition will work as an input parameter to a function, but a simple array wont

Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 11th Jul 2003 08:17
or with people missing the question altogether could try this...




you could then use that to have a 3D Vector that works identical to DBP's

you could pass the actual vector into function either by the vector number or by the pointer and use the pointer to grab the actual data allowing it to be a more open version of the vectoring structures

swdave
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United States
Posted: 11th Jul 2003 21:10
The question was....

@pat1926
Quote: "
Is it possible to have a funciton with types as the inputs?
"

No it dont work......

@indi

Quote: "the above snippet was missing the global statement for it to work"


I use patch 4.1 it doesnt require the global, you might be using something else but I will take your advice instead of learn the hard way on the next patch

@Raven

Why dont u get a job?

NASA is looking for programmers to go on the next Mars expedition.

You can still post here but it will just take a bit longer for us to see it .

Dave...

Login to post a reply

Server time is: 2026-07-18 07:32:02
Your offset time is: 2026-07-18 07:32:02