Passing variable parameters to and from a method.
RichardF
Posts: 168
Just getting started with the Spin language. I am studying the manual and looking at code examples on this forum. What is eluding me is how to pass a variable parameter value back to the calling object or method after it has been changed by the called method. In Pascal, C and QBasic you could send a variable to a procedure by reference (the address where the variable value resided, also use pointers) and then the calling program had access to any changes made by the called procedure. It appears to me that with Spin I can only pass a value·argument·to a method and therefore·lose all ability to see any changes in the passed variable after the called method changes it. What am I missing here?
Example:
Long· stack0[noparse][[/noparse]10]
Byte· temperature
Pub main
· Cognew(Outside_temperature(temperature), stack0)
· dira[noparse][[/noparse]16..23]~~
· repeat·
··· outa[noparse][[/noparse]16..23] := temperature
··· ... do something else...
Pri Outside_temperature(temp)
· temp := ...a process to read a temp probe
I want true parallel processing, e.g.·main can read·outside temperature whenever·it wants·to.
Thanks,
Richard
P.S. We all know I am missing something simple here, so let it rip; I have thick skin .
Example:
Long· stack0[noparse][[/noparse]10]
Byte· temperature
Pub main
· Cognew(Outside_temperature(temperature), stack0)
· dira[noparse][[/noparse]16..23]~~
· repeat·
··· outa[noparse][[/noparse]16..23] := temperature
··· ... do something else...
Pri Outside_temperature(temp)
· temp := ...a process to read a temp probe
I want true parallel processing, e.g.·main can read·outside temperature whenever·it wants·to.
Thanks,
Richard
P.S. We all know I am missing something simple here, so let it rip; I have thick skin .
Comments
On Cognew you pass the address of the variable temperature to the method, where you have to use the keyword BYTE to access the address as byte. There exist also keywords for WORD and LONG to access the memory at this size.