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 / Simple pointer and address question

Author
Message
AleNofx
22
Years of Service
User Offline
Joined: 20th Sep 2003
Location:
Posted: 20th Sep 2003 18:00 Edited at: 20th Sep 2003 18:03
Will this exemple code set the address of the "number" variable in the "ptr" pointer?

number as integer
ptr as dword
ptr = &number

If it doesn't, there's a function that return the address of a variable (not "make memory")?

Thanks to everyone!
ps: excuse for my bad english
empty
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 20th Sep 2003 18:10
For both questions the answer is no.

I awoke in a fever. The bedclothes were all soaked in sweat.
She said "You've been having a nightmare and it's not over yet"
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Sep 2003 19:16
The only variable types that you can get a pointer to are strings (pointer to the string data) and array items.

Both are available with TPC plug-ins only ... both are available for download on my site
AleNofx
22
Years of Service
User Offline
Joined: 20th Sep 2003
Location:
Posted: 21st Sep 2003 04:20
Thank you IanM.. I've tried your Matrix1Array plugin with this code and it works very well!

type myType
a as integer
b as float
endtype

dim final(0) as myType

setTest(get array ptr( final() ) )

print final(0).a
print final(0).b
print get array size( final() )

wait key

function setTest(address as dword)
dim temp(0) as myType
link array to pointer temp(), address
temp(0).a=10
temp(0).b=0.5
unlink array pointer temp()
endfunction

Only one thing..

why with "dim final(0) as myType" the "print get array size( final() )" display "1", with final(1) display 2, final(2) -> 3, etc.. ?

I'm thinking that (for exemple) "dim array(5)" makes an array with 5 elements, than to access the first element the index is 0, the second is 1, etc..

Thank you anyway!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Sep 2003 12:51
The number that you specify in the dim command is the highest index to the array. That means that DBPro is allocating space for that number of entries [/b]plus 1 more[/b] - from zero to the number you specify.

Login to post a reply

Server time is: 2026-07-25 07:00:22
Your offset time is: 2026-07-25 07:00:22