Page 1 of 1
Structure as a procedure parameter
Posted: Fri Mar 13, 2015 12:30 pm
by SeaWolf
Hello,
Here is a simplified example to show the problem I'm having :
Code: Select all
Structure Config
Colour$
EndStructure
Procedure showSettings(*settings.Config)
MessageRequester("", *settings\Colour$)
EndProcedure
Procedure updateSettings(*settings.Config)
*settings\Colour$ = "blue"
showSettings(@settings)
EndProcedure
settings.Config
updateSettings(@settings)
So, showSettings is called from updateSettings, but the MessageRequester shows that
*settings\Colour$ is empty...
What is wrong ? Probably something about the pointers, I'm not sure I understand everything about that

Re: Structure as a procedure parameter
Posted: Fri Mar 13, 2015 12:37 pm
by Shardik
In procedure updateSettings() simply change
to
because settings and *settings are different variables. An EnableExplicit at the beginning would have informed you about that...

Re: Structure as a procedure parameter
Posted: Fri Mar 13, 2015 1:22 pm
by SeaWolf
Thank you Shardik, I don't know how I missed that! Now it works nicely

Re: Structure as a procedure parameter
Posted: Sun Sep 25, 2016 12:59 pm
by Yuri_D
Hi!
Could anybody explain please the difference between Proc( @structure) and Proc( structure) calls for:
Code: Select all
Procedure.i Proc( *struct.structure)
Both are working... Which one is correct?
BRG Yury
Re: Structure as a procedure parameter
Posted: Sun Sep 25, 2016 2:57 pm
by StarBootics
Yuri_D wrote:Hi!
Could anybody explain please the difference between Proc( @structure) and Proc( structure) calls for:
Code: Select all
Procedure.i Proc( *struct.structure)
Both are working... Which one is correct?
BRG Yury
This is the good way :
Code: Select all
Structure Config
Colour$
EndStructure
Procedure showSettings(*settings.Config)
MessageRequester("", *settings\Colour$)
EndProcedure
Procedure updateSettings(*settings.Config)
*settings\Colour$ = "blue"
showSettings(*settings)
EndProcedure
settings.Config
updateSettings(settings)
Re: Structure as a procedure parameter
Posted: Sun Sep 25, 2016 8:00 pm
by Demivec
Yuri_D wrote:Could anybody explain please the difference between Proc( @structure) and Proc( structure) calls for:
Code: Select all
Procedure.i Proc( *struct.structure)
Both are working... Which one is correct?
They are both the same.
It is true that a structure used as a parameter currently and in the past versions of PureBasic, will always send its address and not its contents but good code etiquette would probably say that you should explicitly show that you are using the address of the structure (@structure) itself to avoid confusion.
To the contrary I personally prefer to usually leave off the '@' operator in this case.

Re: Structure as a procedure parameter
Posted: Mon Sep 26, 2016 10:16 am
by Yuri_D
Hi!
Thank you for the explanation!
BRG
Yury