Created
January 28, 2015 18:28
-
-
Save goertzenator/1e90c2d53d131d159829 to your computer and use it in GitHub Desktop.
static c string test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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