Just starting out? Need help? Post your questions and find answers here.
luis
Addict
Posts: 3895 Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy
Post
by luis » Sun Dec 28, 2008 11:11 pm
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...
Psychophanta
Always Here
Posts: 5153 Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:
Post
by Psychophanta » Sun Dec 28, 2008 11:36 pm
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.
freak
PureBasic Team
Posts: 5946 Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany
Post
by freak » Sun Dec 28, 2008 11:40 pm
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
Psychophanta
Always Here
Posts: 5153 Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:
Post
by Psychophanta » Sun Dec 28, 2008 11:44 pm
Whith that you have gave me this mad idea...
... what if:
Code: Select all
Structure StructA
p.StructB
EndStructure
Structure StructB
p.StructA
EndStructure
Kaeru Gaman
Addict
Posts: 4826 Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany
Post
by Kaeru Gaman » Mon Dec 29, 2008 12:47 am
I agree: it is a mad idea...
oh... and have a nice day.
Mistrel
Addict
Posts: 3415 Joined: Sat Jun 30, 2007 8:04 pm
Post
by Mistrel » Mon Dec 29, 2008 12:55 am
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
Posts: 5946 Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany
Post
by freak » Mon Dec 29, 2008 1:00 am
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
idle
Always Here
Posts: 6025 Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand
Post
by idle » Mon Dec 29, 2008 1:07 am
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
luis
Addict
Posts: 3895 Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy
Post
by luis » Mon Dec 29, 2008 1:15 am
freak wrote: It is to allow references to structrures which will be defined later.
OK, make sense.
Thank you.
srod
PureBasic Expert
Posts: 10589 Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...
Post
by srod » Mon Dec 29, 2008 12:50 pm
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.