[Possible Bug ] Pointers & Structures

Just starting out? Need help? Post your questions and find answers here.
Mijikai
Posts: 12
Joined: Sun Sep 17, 2017 9:59 am

[Possible Bug ] Pointers & Structures

Post by Mijikai »

Maybe its just me - but there could be a bug !

Testcode (SpiderBasic 2.10 - Demo):
http://forums.spiderbasic.com/viewtopic ... 1282#p4439
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: [Possible Bug ] Pointers & Structures

Post by falsam »

Confirm

■ This example is correct

Code: Select all

Structure NewDummy
  foo1.s
  foo2.i
EndStructure

Global  *Dummy.NewDummy
*Dummy = AllocateMemory(SizeOf(NewDummy))
*Dummy\foo1 = "hello"

Debug *Dummy\foo1
■ This This example generates a javascript error

Code: Select all

Structure NewDummy
  foo1.s
  foo2.i
EndStructure

Structure Dummy
  Test.NewDummy
EndStructure

Global  *Dummy.Dummy
*Dummy = AllocateMemory(SizeOf(Dummy))
*Dummy\Test\foo1 = "Hello" ;console.log say "Cannot set property '_foo1' of undefined"

Debug *Dummy\Test\foo1

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: [Possible Bug ] Pointers & Structures

Post by Fred »

Unlike PureBasic, you can't use a flat memory buffer and use a structure on it. You need to use AlllocateStructure() if you want dynamically allocated structures

Code: Select all

Structure NewDummy
  foo1.s
  foo2.i
EndStructure

Structure Dummy
  Test.NewDummy
EndStructure

Global  *Dummy.Dummy
*Dummy = AllocateStructure(Dummy)
*Dummy\Test\foo1 = "Hello" ;console.log say "Cannot set property '_foo1' of undefined"

Debug *Dummy\Test\foo1
Post Reply