Pointer to unstructured var

Just starting out? Need help? Post your questions and find answers here.
Sirius-2337
Posts: 35
Joined: Wed Mar 26, 2014 5:47 pm

Pointer to unstructured var

Post by Sirius-2337 »

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

Re: Pointer to unstructured var

Post by Fred »

In SB, pointer has to point to a same structured element, or it won't work.
User avatar
skywalk
Posts: 55
Joined: Tue Feb 25, 2014 2:13 am
Location: Boston, MA

Re: Pointer to unstructured var

Post by skywalk »

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

Re: Pointer to unstructured var

Post by Fred »

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)
User avatar
skywalk
Posts: 55
Joined: Tue Feb 25, 2014 2:13 am
Location: Boston, MA

Re: Pointer to unstructured var

Post by skywalk »

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

Re: Pointer to unstructured var

Post by Fred »

No, but it needs to be properly documented, that's true.
Post Reply