Skip to content

Instantly share code, notes, and snippets.

@goertzenator
Created January 28, 2015 18:28
Show Gist options
  • Save goertzenator/1e90c2d53d131d159829 to your computer and use it in GitHub Desktop.
Save goertzenator/1e90c2d53d131d159829 to your computer and use it in GitHub Desktop.
static c string test
extern crate libc;
use libc::c_int;
use libc::c_uchar;
extern {
fn puts(s:*const c_uchar) -> c_int;
}
// this works! :D
fn puts_test1() {
unsafe { puts(&b"hello using puts\n\0"[0]); }
()
}
// this doesn't :(
const CONST_C_STR: *const c_uchar = &b"a constant c string\n\0"[0];
fn puts_test2() {
unsafe { puts(CONST_C_STR); }
()
}
fn main() {
puts_test1();
puts_test2()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment