Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelseakomlo/e6ec60b0a596c6d924a508d14077d791 to your computer and use it in GitHub Desktop.
Save chelseakomlo/e6ec60b0a596c6d924a508d14077d791 to your computer and use it in GitHub Desktop.
CString
extern crate libc;
use libc::c_char;
use std::ffi::CString;
fn get_string() -> String {
String::from("hello world!")
}
#[no_mangle]
pub unsafe extern "C" fn c_get_string() -> *mut c_char {
let new_str = get_string();
let c_new = CString::new(new_str).unwrap();
c_new.into_raw()
}
fn main() {
println!("{}", get_string());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment