Hello,

I'd like to ask a naive question about Rust/C FFI. Say I have a C struct
which, among other things, has a function pointer:

#[repr(C)]
struct CStruct {
  data: libc::c_int,
  callback: extern fn(libc::uint8_t)
}

And I would like to create an instance of this struct, but I would like to
make that function pointer be NULL. How should I set the callback field of
the struct so that C functions see a NULL pointer there? I have tried:

let cs = CStruct {
  data: 0,
  callback: ptr::null(),
};

As well as:

let cs = CStruct {
  data: 0,
  callback: mem::transmute(ptr::null()),
};

But both give compile errors. Any pointers (heh) about this problem?

Thanks for your help!

Frank
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to