Structure and memory Pointers

Just starting out? Need help? Post your questions and find answers here.
GenRabbit
Enthusiast
Enthusiast
Posts: 151
Joined: Wed Dec 31, 2014 5:41 pm

Structure and memory Pointers

Post by GenRabbit »

Why will it not allow this?

Code: Select all

EnableExplicit
Structure Hello
	me.i
	*you
EndStructure
Define p.hello
p\me = 0
p\*you = AllocateMemory(1000)
FreeMemory(p\*you)
Tried it with you.point, not working either
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Structure and memory Pointers

Post by mk-soft »

Pointer inside structures write without * ;)

Code: Select all

EnableExplicit
Structure Hello
	me.i
	*you
EndStructure
Define p.hello
p\me = 0
p\you = AllocateMemory(1000)
FreeMemory(p\*you)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
GenRabbit
Enthusiast
Enthusiast
Posts: 151
Joined: Wed Dec 31, 2014 5:41 pm

Re: Structure and memory Pointers

Post by GenRabbit »

Thanks, in the online manual it says *ptr and ptr is two different variables, yet in structure its is the same...
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: Structure and memory Pointers

Post by PBJim »

GenRabbit wrote: Sun Nov 17, 2024 4:32 pm Thanks, in the online manual it says *ptr and ptr is two different variables, yet in structure its is the same...
I remembered seeing something in the manual about this and just checked. In the PDF versions, on page 248 of the shorter version, or 276 of the full version, it mentions that the * is omitted. But yes, you're right, it seems a bit of an exception.

Example: Pointers — from https://www.purebasic.com/documentation ... cSmall.pdf

Code: Select all

Structure Person
  *Next.Person ; Here the ’* ’ is mandatory to declare a pointer
  Name$
  Age.b
EndStructure

Timo.Person\Name$ = "Timo"
Timo\Age = 25

Fred.Person\Name$ = "Fred"
Fred\Age = 25

Timo\Next = @Fred ; When using the pointer, the ’* ’ is omitted
Post Reply