Just starting out? Need help? Post your questions and find answers here.
Sirius-2337
Posts: 35 Joined: Wed Mar 26, 2014 5:47 pm
Post
by Sirius-2337 » Sun Feb 14, 2016 9:47 am
Can't access a unstructured vars value with pointers
x is 'undefined'
y is ok (96)
Code: Select all
Structure Inti
i.i
EndStructure
Procedure Something()
Protected x, y.Inti
Protected *PointerToX.Inti, *PointerToY.Inti
x = 76
y\i = 96
*PointerToX = @x
*PointerToY = @y
Debug *PointerToX\i
Debug *PointerToY\i
EndProcedure
Something()
Firefox, Chrome, SB1.20
In PB this works
Fred
Site Admin
Posts: 1820 Joined: Mon Feb 24, 2014 10:51 am
Post
by Fred » Sun Feb 14, 2016 2:07 pm
In SB, pointer has to point to a same structured element, or it won't work.
skywalk
Posts: 55 Joined: Tue Feb 25, 2014 2:13 am
Location: Boston, MA
Post
by skywalk » Sun Feb 14, 2016 4:32 pm
Is this a limitation of JS? We can still manipulate via memory lib.
Code: Select all
Define *p.Double = AllocateMemory(SizeOf(Double))
Define.d x = 100.0
Define.i i = 99
*p\d = x
PokeD(*p, 0, -9.9)
Debug PeekD(*p, 0)
PokeL(*p, 0, i)
Debug PeekL(*p, 0)
PokeA(*p, 0, 1)
Debug PeekL(*p, 0)
When working toward the solution of a problem, it always helps if you know the answer. ~ ?
An expert is one who knows more and more about less and less until he knows absolutely everything about nothing. ~ Weber
Fred
Site Admin
Posts: 1820 Joined: Mon Feb 24, 2014 10:51 am
Post
by Fred » Sun Feb 14, 2016 5:36 pm
Regular variables are not based on arraybuffer, it would be too slow. BTW, the first *p\d = x doesn't work, as it creates a new field in the object.
Code: Select all
Define *p.Double = AllocateMemory(SizeOf(Double))
Define.d x = 100.0
Define.i i = 99
*p\d = x
Debug PeekD(*p, 0)
skywalk
Posts: 55 Joined: Tue Feb 25, 2014 2:13 am
Location: Boston, MA
Post
by skywalk » Sun Feb 14, 2016 6:27 pm
Yeah, that is confusing. Is this not considered a bug?
When working toward the solution of a problem, it always helps if you know the answer. ~ ?
An expert is one who knows more and more about less and less until he knows absolutely everything about nothing. ~ Weber
Fred
Site Admin
Posts: 1820 Joined: Mon Feb 24, 2014 10:51 am
Post
by Fred » Sun Feb 14, 2016 6:57 pm
No, but it needs to be properly documented, that's true.