Passing a field of a structure pointer to a procedure

Just starting out? Need help? Post your questions and find answers here.
Knotz
New User
New User
Posts: 3
Joined: Mon Jun 11, 2007 10:59 am

Passing a field of a structure pointer to a procedure

Post by Knotz »

I have the following code:

Code: Select all

Structure Foo
  A.l
  B.f
  C.s
EndStructure

Structure Bar
  F.Foo
EndStructure

NewList Bars.Bar()

Procedure SetC(*F.Foo,S.s)
  *F\C = S
EndProcedure

*Q.Bar = AddElement(Bars())

SetC(*Q\F,"DING")   ;; << correct
Debug *Q\F\C

SetC(@*Q\F,"DONG") ;; << also correct
Debug *Q\F\C
Is SetC(*Q\F,"DING") and SetC(@*Q\F,"DING") the same?

In the former case it seems that i'm passing Foo by value and the latter by "reference" (pointer actually).

btw. I'm using the latest 4.10 Beta 2 for Win.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

In both cases it is by reference.

Perhaps this helps:

Code: Select all

Structure Foo 
  A.l 
  B.f 
  C.s 
EndStructure 

a.foo

Debug @a
Debug a  ;<< Same output as above!
I may look like a mule, but I'm not a complete ass.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Structures are always passed by reference in PB.
Knotz
New User
New User
Posts: 3
Joined: Mon Jun 11, 2007 10:59 am

Post by Knotz »

Ok, thanks a lot for the fast answers.
Post Reply