paint-brush
Things you can’t do in Rust: variadic functionsby@andrew_lucker
1,579 reads
1,579 reads

Things you can’t do in Rust: variadic functions

by Andrew LuckerDecember 5th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

I love Rust and want it to be better. The dev teams know about all issues presented. I just want to generate discussion and enthusiasm for making a good language better.
featured image - Things you can’t do in Rust: variadic functions
Andrew Lucker HackerNoon profile picture

I love Rust and want it to be better. The dev teams know about all issues presented. I just want to generate discussion and enthusiasm for making a good language better.








#![feature(c_variadic)]#[no_mangle]pub unsafe extern "C" fn func(fixed: u32, mut args: ...) {let x: u8 = args.arg();let y: u16 = args.arg();let z: u32 = args.arg();println!("{} {} {} {}", fixed, x, y, z);}

Result (compile time error):




error[E0554]: #[feature] may not be used on the stable release channel|1 | #![feature(c_variadic)]| ^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error(s)

Rust has variadic macros. Rust can use C variadic functions. RFC 2137 covers only the case of defining variadic functions from within Rust. This is hard to think about garbage collection and lifetimes, so this feature may get restricted to ground types or similar compromises. Maybe this is just overlapping with macros and the feature is unnecessary.