Page 1 of 1

Passing a field of a structure pointer to a procedure

Posted: Wed Jul 04, 2007 9:56 am
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.

Posted: Wed Jul 04, 2007 10:07 am
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!

Posted: Wed Jul 04, 2007 10:22 am
by Trond
Structures are always passed by reference in PB.

Posted: Wed Jul 04, 2007 10:25 am
by Knotz
Ok, thanks a lot for the fast answers.