Pointers to variable or structure?

Just starting out? Need help? Post your questions and find answers here.
Sensphere
User
User
Posts: 19
Joined: Tue May 27, 2003 3:44 pm
Location: Germany/Stuttgart
Contact:

Pointers to variable or structure?

Post by Sensphere »

Why does this work:

Code: Select all

a.POINT
*b.POINT
a\x  = 0
*b = @a
*b\x = -1
CallDebugger
Debug a\x
Changed the x value of a successfully!

But this one will not:

Code: Select all

a.l
*b.l
a  = 0
*b = @a
*b = -1
CallDebugger
Debug a\x
Isn't it possible to get a pointer to a long variable (or anything other than a structure)???
__ i know that i know nothing __
__ those who swim with the stream will never reach the source __
(K7 XP @ 2.4 GHz | WinXP SP1 | 1 GB RAM | ATI Radeon 7500 | PB 3.81 [Win|Linux])
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: Pointers to variable or structure?

Post by GPI »

In the second is a bug: it should call debug a not a\x

Try this:

Code: Select all

a.l
*b.long
a  = 0
*b = @a
*b\l = -1

Debug a
Isn't it possible to get a pointer to a long variable (or anything other than a structure)???[/quote]
Sensphere
User
User
Posts: 19
Joined: Tue May 27, 2003 3:44 pm
Location: Germany/Stuttgart
Contact:

Re: Pointers to variable or structure?

Post by Sensphere »

Ok, this is working :D - but isn't it a bit weird - because a pointer to a long value shouldn't be a structure?!
GPI wrote:In the second is a bug: it should call debug a not a\x

Try this:

Code: Select all

a.l
*b.long
a  = 0
*b = @a
*b\l = -1

Debug a
Isn't it possible to get a pointer to a long variable (or anything other than a structure)???
[/quote]
__ i know that i know nothing __
__ those who swim with the stream will never reach the source __
(K7 XP @ 2.4 GHz | WinXP SP1 | 1 GB RAM | ATI Radeon 7500 | PB 3.81 [Win|Linux])
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: Pointers to variable or structure?

Post by tinman »

Sensphere wrote:Ok, this is working :D - but isn't it a bit weird - because a pointer to a long value shouldn't be a structure?!
PureBasic's pointer notation is simpler than e.g. C, so there is no way to access both the pointer and the data within for simple data types without making it point to a structure which contains the simple data type.

Or use Peek and Poke :)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Post Reply