Spinroot

A forum for Spin users

You are not logged in.

#1 2018-11-14 17:47:07

DavidFarago
Member
Registered: 2011-10-17
Posts: 21

Hiding "local" variable yields error "cannot hide non-globals"

Hello,

I have the following structure:

    inline foo(parameter) {
      d_step {
        struct_type struct_local_var;
        <code block that is the only one using struct_local_var>
      }
    }

To safe some memory, I wanted to switch to

    hidden struct_type struct_local_var;

However, I get the error message

    spin: ./foo.pml:29, Error: cannot hide non-globals (_12_5_6_8_struct_local_var)

What is a "non_global", and why is struct_local_var one? How can I enable hiding struct_local_var?


Best
David

Offline

#2 2018-11-22 18:36:57

spinroot
forum
Registered: 2010-11-18
Posts: 695
Website

Re: Hiding "local" variable yields error "cannot hide non-globals"

Any variable is either global or local. So, a non-global means a local variable.
A variable is global if declared outside all proctypes.
An inline can only be inlined inside a proctype, so anything declared inside an inline
is automatically classified as a local variable.

Offline

#3 2018-11-25 20:47:38

DavidFarago
Member
Registered: 2011-10-17
Posts: 21

Re: Hiding "local" variable yields error "cannot hide non-globals"

Thank you for this concise explanation.

Too bad that local variables cannot be hidden. Do they not contribute just like global variables to the state vector?

Since I prefer smallest possible scopes, my variables that are solely used inside one d_step are always local and hence not hideable. Could this be changed in Spin? That would be awesome, because I have many of those variables.

Otherwise, what are the disadvantages if I make such a variable global just for the purpose of hiding it? Since it is hidden, turning it global will not deteriorate POR, will it?


Thanks,
David

Offline

#4 2018-11-25 22:21:46

spinroot
forum
Registered: 2010-11-18
Posts: 695
Website

Re: Hiding "local" variable yields error "cannot hide non-globals"

Good point, but if you make sure that the temporary variable (e.g., used only inside a d_step)
is reset to 0 before the d_step returns, then its value will not contribute to the state vector.
So in that case it's similar to being "hidden" -- it's always zero where it is visible to Spin.

Offline

Board footer

Powered by FluxBB