pointer to a not defined struct in struct

Just starting out? Need help? Post your questions and find answers here.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

pointer to a not defined struct in struct

Post by luis »

Code: Select all

Structure TEST
a.i
b.whatisthat
EndStructure
the compiler gives an error in this case

Code: Select all

Structure TEST
a.i
*b.whatisthat
EndStructure
but nothing in this case

Has this been reported already ?

I believe I saw something similar posted in the forum but I'm not sure...
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

The compiler ignores the type of the pointer vars.
A pointer is indeed always a .i variable (so then a .i length variable), but it points to a specific type of data, which, in my opinion, should be written just like your example does.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
freak
PureBasic Team
PureBasic Team
Posts: 5946
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

It is to allow references to structrures which will be defined later.

Otherwise something like this would not be possible:

Code: Select all

Structure StructA
  *p.StructB
EndStructure

Structure StructB
  *p.StructA
EndStructure
quidquid Latine dictum sit altum videtur
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Whith that you have gave me this mad idea...
... what if:

Code: Select all

Structure StructA 
  p.StructB 
EndStructure 

Structure StructB 
  p.StructA 
EndStructure
:?:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

I agree: it is a mad idea...
oh... and have a nice day.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

freak wrote:It is to allow references to structrures which will be defined later.
Is this kind of behavior necessary in a single-pass compiler?
freak
PureBasic Team
PureBasic Team
Posts: 5946
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Psychophanta wrote:Whith that you have gave me this mad idea...
... what if:

Code: Select all

Structure StructA 
  p.StructB 
EndStructure 

Structure StructB 
  p.StructA 
EndStructure
:?:
If this worked, there would be endless recursion.

> Is this kind of behavior necessary in a single-pass compiler?

Well, you could also have a way to declare a structure before actually defining its content (like you can do in C) but thats a bit overkill imho.
quidquid Latine dictum sit altum videtur
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Post by idle »

why the question?

Code: Select all


Structure StructA
  *p.StructB
   mdat.i
   something.w
   another.w
EndStructure

Structure StructB
  *p.StructA
   mdat.i
EndStructure 

mA.StructA
mB.StructB

ma\mdat = 999
mb\mdat = 666

mA\p = @mb 
mb\p = @ma 

Debug  ma\mdat        
Debug  mA\p\mdat 

Debug  mb\mdat   
Debug  mb\p\mdat 

Mindyou pointer references like this, mostly do my head in :?

And it can make it tricky dealing with structures in C libs

when they reference each other without pointers
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Post by luis »

freak wrote:It is to allow references to structrures which will be defined later.
OK, make sense.

Thank you.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

For God's sake do not change this behaviour - my code relies on it quite heavily!
I may look like a mule, but I'm not a complete ass.
Post Reply