Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Guidance on how to pass null for a pointer to a pointer
I've not done much rust so i've jumped off at the deep end to by doing some FFI C calls. I'm unsure of the correct way to make one of my calls.
I have a C function which has the signature something like
void f(char** buf);
In C you can do these two calls.
char* buf;
f(&buf); // Function returns a pointer to something and does something
f(NULL); // Function does something but doesn't return a pointer.
fn f(buf : &*mut libc::c_void);
?let mut buf : [i8; 5] = [1,2,3,4,5];
unsafe{f(& buf.as_mut_ptr());} // seems to work but I'm not entirely sure it is correct.
unsafe{f(& *ptr::null_mut());} // I get the warning 'this code causes undefined behavior when executed'
8 posts - 6 participants
🏷️ Rust_feed