Skip to content

Commit 493934b

Browse files
lolsob
1 parent 534d79a commit 493934b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ compile-flags: --edition 2021
2+
use core::ffi;
3+
4+
extern "C" {
5+
fn printf(ptr: *const ffi::c_char, ...) -> ffi::c_int;
6+
}
7+
8+
fn generic_printf<T>(c: &ffi::CStr, arg: T) {
9+
unsafe { printf(c.as_ptr(), arg) };
10+
}
11+
12+
fn main() {
13+
generic_printf(c"%d", 2u8);
14+
generic_printf(c"%f", 3.333_f32);
15+
generic_printf(c"%s", vec![6, 2, 8, 3, 1, 8, 5, 3, 0]);
16+
}

0 commit comments

Comments
 (0)