when I tried it didn't compile
Can Structures Have Pointers?
Can Structures Have Pointers?
Is there a way to have a structure field point to another structure so it can access the fields in that structure so the stucture can have dynamic fields
when I tried it didn't compile
when I tried it didn't compile
~Dreglor
there many examples scattered about, try searching for structure+pointer
here's one example.
here's one example.
Pupil wrote:use a pointer and use a dummy array to access it.You have to check so you don't go out of bounds or you will surely have a crash.. I guess you could just as easily use the AllocateMemory() command, but then you have to keep track of the memory bank number also...Code: Select all
structure testtype a.l b.s parray.l ; array pointer endstructure structure dummytype value.l[0] endstructure a.testtype\parray = GlobalAlloc_(#GMEM_FIXED|#GMEM_ZEROINIT, 1024*4) *b.dummytype = a\parray for i = 0 to 10 *b\value[i] = i debug *b\value[i] next globalfree_(a\parray)
These two point at each other.
Code: Select all
Structure myFirstStructure
PointsToB.l
itemA.l
EndStructure
Structure myOtherStructure
addressOfA.l
thingB.l
EndStructure
thisIsFirst.myFirstStructure
anotherOne.myOtherStructure
thisIsFirst\itemA=1
thisIsFirst\PointsToB=@anotherOne
anotherOne\thingB=2
anotherOne\addressOfA=@thisIsFirst
*pA.myFirstStructure=anotherOne\addressOfA
Debug *pA\itemA
Debug thisIsFirst\itemA
*pB.myOtherStructure=thisIsFirst\PointsToB
Debug *pB\thingB
Debug anotherOne\thingB@}--`--,-- A rose by any other name ..
Is this what you're looking for?
Code: Select all
Structure struct1
StructureUnion
b.b
w.w
l.l
EndStructureUnion
EndStructure
Structure struct2
*a.struct1
EndStructure
b.struct1\l = $10203040
a.struct2\a = @b
Debug "$"+Hex(a\a\b)
Debug "$"+Hex(a\a\w)
Debug "$"+Hex(a\a\l)


