Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The rules of C++ state that inline function definitions will work correctly with static local variables. That is, if you inline function definitions, any local static variables will all be referring to the same variable.</p> <p><em><strong>However</em></strong>, there is one thing C++ does <em>not</em> define: DLLs.</p> <p>The C++ specification is completely ignorant of DLLs; it has no idea how to handle them. C++ is defined in terms of <em>static</em> linkage, not dynamic.</p> <p>As such, this means that the specification <em>no longer applies</em> when dealing with DLL boundaries. And that's where your problem comes from.</p> <p>While C++ requires that inline functions with local static variables still work, C++ having no knowledge of DLLs means that everything is up to what the <em>compiler</em> decides to do.</p> <p>It is perfectly legitimate compiler behavior for inline functions split across DLL boundaries to not have local static variables work as expected. It's such an outlier case that I seriously doubt any compiler developers spent time coding for such an eventuality.</p> <p>The most reasonable thing for a compiler to do is exactly what it would do if you declared a extern global variable in a DLL header: each DLL and executable gets a <em>separate</em> one. That's why you need special syntax to say that a definition should be defined a by this executable/DLL (<code>__declspec(dllexport)</code>) and what will come from some other executable/DLL (<code>__declspec(dllimport)</code>).</p> <p>You must <em>always</em> be careful of what you put across DLL boundaries. In general, don't inline things across DLL boundaries like this.</p>
 

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