Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement