Page 1 of 1

Pointer to unstructured var

Posted: Sun Feb 14, 2016 9:47 am
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 :)

Re: Pointer to unstructured var

Posted: Sun Feb 14, 2016 2:07 pm
by Fred
In SB, pointer has to point to a same structured element, or it won't work.

Re: Pointer to unstructured var

Posted: Sun Feb 14, 2016 4:32 pm
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)

Re: Pointer to unstructured var

Posted: Sun Feb 14, 2016 5:36 pm
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)

Re: Pointer to unstructured var

Posted: Sun Feb 14, 2016 6:27 pm
by skywalk
Yeah, that is confusing. Is this not considered a bug?

Re: Pointer to unstructured var

Posted: Sun Feb 14, 2016 6:57 pm
by Fred
No, but it needs to be properly documented, that's true.