Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In practice, space for static storage can be allocated as part of the initial binary loading, or by the runtime during startup; but will always happen before user code is encountered.</p> <p>In addition to the constraints that <em>Kerrek SB</em> mentions, the storage for a <code>const expr</code> value could be eliminated if the value itself is never used at runtime.</p> <p>This wouldn't necessarily mean that the value needs to not be evaluated - if a static <code>const expr</code> were only used as a branch condition, that condition may be evaluated statically and other code paths may not be generated or may be excluded by the optimiser.</p> <p>Pretty much any storage with <code>static</code> duration may be eliminated if the implementation can guarantee behaviour as though the storage were present - i.e. a comparison expression that can be evaluated at compile time - like a different <code>const expr</code>, a pointer comparison where the rhs is known to be an alias to a different variable, or perhaps an incompatible type. It may also be eliminated if the value is only read into variables that are never read themselves; or where the value may be reduced to a <code>const expr</code>.</p> <pre><code>struct Foo{}; static Foo bar; // static instance Foo* func() { if ( ! (&amp;bar) ) { // always non-NULL // this block may be eliminated Foo* myCopy(new Foo(bar)); return myCopy; } // so 'bar' is never referred to, and we know it has no side- // effects, so the static variable can be eliminated return new Foo(); } </code></pre> <blockquote> <p><strong>3.7.1 Static storage duration</strong></p> <blockquote> <p><code>2.</code> If an object of static storage duration has initialization or a destructor with side effects, it shall not be eliminated even if it appears to be unused, except that a class object or its copy may be eliminated as specified in 12.8.</p> </blockquote> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload