Oxygen Basic
Programming => Example Code => Topic started by: Brian Alvarez on November 30, 2018, 01:04:53 AM
-
If somebody can provide an example for this, i would appreciate it.
I see that TYPE allows PTR members,
TYPE SOMETHING
SOMETHING AS LONG PTR
END TYPE
How can those be used?
-
A simple demo for setting pointered members:
type tt
pf as float ptr
end type
dim t as tt
dim f as float=pi()
@t.pf=@f
print t.pf
-
I think i understand. I would need to split the assignation into several statements, right?
The way i am trying to emulate is this, suppose i have a variable for an UDT PTR. As follows:
type tt
pf as float ptr
end type
dim t as tt ptr
The way i would do it in PowerBASIC would be to aquire an address for t like this:
t = hAddress
And then i would need to aquire an address for pf, as follows:
@t.pf = hAddress
Then i would access pf member as follows:
@t.@pf = 123
There can even bee deeply nested pointers like this:
@t.@pf.@tree.@yikes = 1234
Am i right to assume in Oxygen i need to do this?
@t = hAddress1
@t.pf = hAddress2
@t.pf.tree = hAddress3
@t.pf.tree.yikes = hAddress4
And if so... am i right to assume this would return the address of an UDT member 'yikes':
print str(@t.pf.tree.yikes)
While this returns the value stored in the member?
print str(t.pf.tree.yikes)
-
Yes, this is correct.
@t = hAddress1
@t.pf = hAddress2
@t.pf.tree = hAddress3
@t.pf.tree.yikes = hAddress4
'
print str(t.pf.tree.yikes)
Fortunately, direct deep pointering is seldom required , though recursive tree stuructures are quite useful.
type tt
pt as tt ptr 'recursive structure
dat[16] as int
end type
-
This is a new concept to me charles, how does it work?
Perhaps i can make use of it. :)
-
A structure can refer to itself using a pointer member, without causing any recursion problems.
You can use it as a node for linked lists, tree structures and networks.
Here is a silly example, but it tests the notation:
'11:38 03/12/2018
'UDT SELF REFERENCE TEST
type tt
int a,b,c
tt* t
end type
tt t
@t.t=@t
t={1,2,3}
print t.b
print t.t.b
print t.t.t.b