You would use an Option and then just pass None. So something like:
#[repr(C)]
struct CStruct {
data: libc::c_int,
callback: Option<extern fn(libc::uint8_t)>
}
On Sep 26, 2014, at 2:05 AM, Frank Huang <[email protected]> wrote:
> 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
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev