title: How to access opaque implementation of a class from an extern "C" friend function in C?
body: <p>In case the title doesn't quite make sense, here's a stripped-down example.  Consider this myclass.h:</p>
  
  <pre><code>// Compiled with g++ 4.7 and -std=c++0x -pedantic -Wall -Wextra on Linux
  class myclass {
  public:
      myclass()=default;
      void init();
  
  private:
     struct myclassImpl;
     static myclassImpl _impl;
  }`   
  </code></pre>
  
  <p>and myclass.cpp</p>
  
  <pre><code>#include &lt;csignal&gt;
  using namespace std;
  #include "myclass.h"
  
  extern "C" {   
      void end_sig(int);
  }   
  
  struct myclass::myclassImpl {
      friend void end_sig(int);
  
      myclassImpl()=default;
      void cleanup();
  }   
  
  myclass::myclassImpl myclass::_impl;
  
  extern "C" {
      void end_sig(int /* sig */) {
          myclass::_impl.cleanup();
      }
  }
  
  void myclass::init() {
      signal (SIGINT, end_sig);
  }
  
  void myclass::myclassImpl::cleanup() {
      // stuff...
  }
  </code></pre>
  
  <p>As you can see, I am trying to implement the bridge or pimpl pattern (and the monostate pattern though I don't think it is relevant to this particular problem.)  Mostly it works but in this particular implementation and not others, I have to make a signal handler which must be an extern "C" function not a method of the class.  If the code is set up like this, I get the following error:</p>
  
  <pre><code>In function ‘void end_sig(int)’:    
  error: ‘myclass::myclassImpl myclass::_impl’ is private
  </code></pre>
  
  <p>I can think of two ways around this.</p>
  
  <ol>
  <li>move the friend declaration into myclass.</li>
  <li>make _impl public.</li>
  </ol>
  
  <p>But in both cases it would violate the seperation of interface and implementation right?  Are there any better alternatives?</p>