SHARE
TWEET

Untitled

a guest Oct 21st, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use libc::c_char;
  2. use std::ffi::CStr;
  3.  
  4. type GiveCChar = extern "C" fn(*const c_char);
  5.  
  6. extern "C" {
  7.     fn hello(give_c_char: GiveCChar);
  8. }
  9.  
  10. fn main() {
  11.     unsafe { hello(print_cstr); }
  12. }
  13.  
  14. extern "C" fn print_cstr(c: *const c_char) {
  15.     let x = unsafe { CStr::from_ptr(c) };
  16.     println!("{:?}", x);
  17. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top