title: extern "C" with class and DLL
body: <p>I was presented with a C++ DLL source code that uses <code>extern "C"</code>:</p>
  
  <pre><code>extern "C"
  {
      class Something
      {
         public:
           __declspec(dllexport) Something();
           __declspec(dllexport) virtual ~Something();
           __declspec(dllexport) bool function_one(const char * some_text);
           static __declspec(dllexport) char * get_version();
         private:
            unsigned int m_data;
      };
  }
  </code></pre>
  
  <p>The DLL is being called by a C++ program.
  FYI, using Visual Studio 2017 on Windows 7 platform.</p>
  
  <p><strong>Questions</strong> *(all related to the <code>extern "C"</code> and <code>class</code>):  </p>
  
  <ol>
  <li>Since <code>class</code> is not C language, will this be equivalent to a
  <code>struct</code>?</li>
  <li>Are constructors valid?</li>
  <li>Are virtual destructors valid (since C doesn't have <code>virtual</code>)?</li>
  <li>How is the <code>bool</code> handled?</li>
  <li>How is <code>static</code> treated inside the <code>extern "C"</code> for the class?</li>
  <li>How is <code>private</code> data handled inside the <code>extern "C"</code> block?</li>
  <li>How is <code>noexcept</code> handled in an <code>extern "C"</code> block for the
  constructor?</li>
  </ol>
  
  <p>The Visual Studio 2017 compiler is not generating any errors or warnings with the above code.  </p>
  
  <p>The VS2017 code analyzer only generates a warning for the constructor:  </p>
  
  <pre><code>C26439 This kind of function may not throw. Declare it 'noexcept' (f.6).
  </code></pre>
  
  <p><strong>Research:</strong><br>
  The questions on StackOverflow related to this issue mention that the "extern "C"<code>has the effect of resolving name mangling.  However, they don't address the issues of</code>virtual<code>,</code>bool`, private data, and etc. as I listed above.  </p>
  
  <p>Also, many DLLs related answers recommend not using non-POD structures because the layout may change between compilers (including same versions of compilers); so for example, character arrays are preferred over <code>std::string</code>.  </p>