title: call swift func from c++ with EXC_BAD_ACCESS(...)
body: <p>I am working on xcode8 swift 3.0 project. It needs to access a C++ library which will need a callback function to send data back to swift caller asynchronizely.
  The callback does work if it is called right inside the RegisterCallBack function.
  However, if it crashes if call it outside the  RegisterCallBack function.</p>
  
  <p>in my swift file ViewController.swift</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
      var closure: () -&gt; Void = testfunc;
      RegisterCallBack(closure)
  
      run_swiftfunc()
  }
  func testfunc(){
      print("test func in view contriller ");
  }
  ....
  </code></pre>
  
  <p>// in my wrapper.h file</p>
  
  <pre><code>...
  void run_swiftfunc();
  void RegisterCallBack(void (^closure)());
  ...
  </code></pre>
  
  <p>// in my wrapper.cpp file</p>
  
  <pre><code>extern "C" {
  typedef void (^callbackfunc)();
  callbackfunc swiftFunc;
  void RegisterCallBack(void (^closure)()){
      swiftFunc = closure;
      printf("function pointer 0x%x \n", (void*) swiftFunc);
      swiftFunc();  //works well 
  }
  void run_swiftfunc(){
     printf("function pointer 0x%x \n", (void*) swiftFunc);
     swiftFunc();   // fail, EXC_BAD_ACCESS
  } 
  ...
  }
  </code></pre>
  
  <p>//log print:
  RegisterCallBack function pointer 0x1300cd30 </p>
  
  <p>run_swiftfunc</p>
  
  <p>function pointer 0x1300cd30 </p>
  
  <p>test func in view contriller </p>
  
  <p>run_swiftfunc</p>
  
  <p>function pointer 0x1300cd30 </p>
  
  <p>(lldb)          ---->EXC_BAD_ACCESS(code =.. </p>
  
  <p>The swiftfunc address is same both are 0x1300cd30. How to preserve the swiftfunc block?</p>