Why can't I declare a shared variable in the same package as the protected type?
<p>I have a simulation helper protected type, which is declared in a package. An instance of that type is defined in the same package. The code is acepted by GHDL, but not by ModelSim.</p>

<p><strong>Is it standard conform?</strong><br>
and<br>
<strong>How can a write a workaround?</strong></p>

<blockquote>
  <p>** Error (suppressible): D:\...\simulation.v08.vhdl(143): (vcom-1257) Shared variable "globalSimStatus" of protected type "T_SIM" cannot be declared before the protected type body.</p>
</blockquote>

<p>My (reduced) package example:</p>

<pre><code>package simulation is
  type T_SIM is protected 
    procedure stop;
  end protected;

  shared variable globalSimStatus : T_SIM;
  -- QuestaSim 10.4c complains that a shared variable can not be declared, before the type's body was parsed.
end package;

package body simulation is
  type T_SIM is protected body
    variable IsStopped : BOOLEAN := FALSE;

    procedure stop is
    begin
      IsStopped := TRUE;
    end procedure;
  end protected body;

  -- This is OK but not global
  shared variable localSimStatus : T_SIM;
end package body;
</code></pre>

<p>One solution could be to define 2 packages: one with the type in it and one with the shared variable.</p>

<p>The disadvantages would be to find a second package name and to import (use) 2 packages in the testbench...</p>

<p>Are there better solutions?</p>

<hr>

<p>I assume QuestaSim wants to know the type's size, which is unknown until all members are parsed.</p>