Just starting out? Need help? Post your questions and find answers here.
POedBoy
New User
Posts: 8 Joined: Tue Jun 01, 2004 9:31 pm
Location: La Verne, CA, USA
Post
by POedBoy » Thu Sep 30, 2004 3:19 pm
Hi all,
I have a procedure that 'creates' and returns a pointer to a structure. I've already tested that and it works fine on its own.
However, I'm having problems using this pointer within another structure. This will come back with syntax errors..(extraneous code snipped):
Code: Select all
Structure HTTP_Connection
*next.HTTP_Connection
*prev.HTTP_Connection
;............
*NetBank.Bank
*url.URL
;............
EndStructure
Procedure.l HTTP_Create()
Protected *hc.HTTP_Connection
*hc = AddElement(HTTP_GlobalList())
*hc\*url.URL = URL_Create() ;<= syntax error
*hc\*NetBank.Bank = Bank_Create(#HTTP_NetBankSize);<= syntax error
;...................
ProcedureReturn *hc
EndProcedure
So what am I doin wrong here? Or is this type of thing just not possible in pure?
Thanks ahead of time.
Pupil
Enthusiast
Posts: 715 Joined: Fri Apr 25, 2003 3:56 pm
Post
by Pupil » Thu Sep 30, 2004 3:30 pm
Your error is that 'Addelement(MyList())' doesn't return the address to the structure. You should do it like this:
Code: Select all
If AddElement(HTTP_GlobalList())
*hc = @HTTP_GlobalList()
; ... etc
Else
Debug "Run out of memory?"
EndIf
POedBoy
New User
Posts: 8 Joined: Tue Jun 01, 2004 9:31 pm
Location: La Verne, CA, USA
Post
by POedBoy » Thu Sep 30, 2004 4:02 pm
I've converted the above procedure to your method, but I still get the same syntax error...
Code: Select all
Procedure.l HTTP_Create()
Protected *hc.HTTP_Connection
;*hc = AddElement(HTTP_GlobalList())
If AddElement(HTTP_GlobalList())
*hc = @HTTP_GlobalList()
; ... etc
Else
Debug "Run out of memory?"
EndIf
;*hc\*url.URL = URL_Create()
If AddElement(URL_GlobalList())
*hc\*url = @URL_GlobalList();<== syntax error still
; ... etc
Else
Debug "Run out of memory?"
EndIf
ProcedureReturn *hc
EndProcedure
I'm not really clear as to why this:
Code: Select all
If AddElement(HTTP_GlobalList())
*hc = @HTTP_GlobalList()
is different than:
Code: Select all
*hc = AddElement(HTTP_GlobalList())
Either way gives me a valid pointer...
tinman
PureBasic Expert
Posts: 1102 Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:
Post
by tinman » Thu Sep 30, 2004 4:53 pm
POedBoy wrote:
I'm not really clear as to why this:
Code: Select all
If AddElement(HTTP_GlobalList())
*hc = @HTTP_GlobalList()
is different than:
Code: Select all
*hc = AddElement(HTTP_GlobalList())
Either way gives me a valid pointer...
They're different pointers. This is explained in the linked list manual. One is a pointer to the user data and the other is the (address of the user data - 8).
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Pupil
Enthusiast
Posts: 715 Joined: Fri Apr 25, 2003 3:56 pm
Post
by Pupil » Thu Sep 30, 2004 7:33 pm
Hmm, i didn't read trough your post thouroughly enough, and what i wrote in my first post was what i saw was wrong by just glancing through your code. Now i've experimented a bit and realized that you need to remove the '*' from the structure path or you'll get a syntax error.
Small example:
Code: Select all
Structure a1
a.l
EndStructure
Structure a2
*a.a1
*b.a1
EndStructure
a.a2\a = @b.l
*p.a2 = @a
b = 1
Debug *p\a\a
POedBoy
New User
Posts: 8 Joined: Tue Jun 01, 2004 9:31 pm
Location: La Verne, CA, USA
Post
by POedBoy » Thu Sep 30, 2004 8:13 pm
Thanks for the help guys..
blueznl
PureBasic Expert
Posts: 6166 Joined: Sat May 17, 2003 11:31 am
Contact:
Post
by blueznl » Fri Oct 01, 2004 8:44 am
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide
right here ... )