title: Cgo: can't set callback in C-struct from Go
body: <p>I have a struct in C lib with some callbacks defined inside it. Problem that Go treat this fields as <code>*[0]byte</code> array type and I can't set it to pointer:</p>
  
  <pre><code>./test.go:16: cannot use _Cgo_ptr(_Cfpvar_fp_cb_func) (type unsafe.Pointer) as type *[0]byte in assignment
  </code></pre>
  
  <p>Sample of problem code:</p>
  
  <pre><code>package main
  
  /*
  void cb_func();
  typedef struct cb_s {
      void (*cb_f)();
  } cb_s;
  */
  import "C"
  
  //export cb_func
  func cb_func() {}
  
  func main() {
          var x C.struct_cb_s
          // here I want to set callback cb_f to pointer of cb_func().
          x.cb_f = C.cb_func
  }
  </code></pre>
  
  <p>One possible solution - write a C setter, something like this:</p>
  
  <pre><code>void cb_set(cb_s *s) {
          s-&gt;cb_f = &amp;cb_func;
  }
  </code></pre>
  
  <p>but it looks ugly: I can't pass cb_func as argument to setter (already tried <code>cb_set(cb_s *s, void(*func)())</code>, but got the same error about *[0]byte) and have many similar callbacks, so need to write setter for each pair of callback - callback function.</p>
  
  <p>Any other solutions?</p>