]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0060.md
Rollup merge of #62514 - stephaneyfx:box-ffi, r=nikomatsakis
[rust.git] / src / librustc_error_codes / error_codes / E0060.md
1 External C functions are allowed to be variadic. However, a variadic function
2 takes a minimum number of arguments. For example, consider C's variadic `printf`
3 function:
4
5 ```
6 use std::os::raw::{c_char, c_int};
7
8 extern "C" {
9     fn printf(_: *const c_char, ...) -> c_int;
10 }
11 ```
12
13 Using this declaration, it must be called with at least one argument, so
14 simply calling `printf()` is invalid. But the following uses are allowed:
15
16 ```
17 # #![feature(static_nobundle)]
18 # use std::os::raw::{c_char, c_int};
19 # #[cfg_attr(all(windows, target_env = "msvc"),
20 #            link(name = "legacy_stdio_definitions", kind = "static-nobundle"))]
21 # extern "C" { fn printf(_: *const c_char, ...) -> c_int; }
22 # fn main() {
23 unsafe {
24     use std::ffi::CString;
25
26     let fmt = CString::new("test\n").unwrap();
27     printf(fmt.as_ptr());
28
29     let fmt = CString::new("number = %d\n").unwrap();
30     printf(fmt.as_ptr(), 3);
31
32     let fmt = CString::new("%d, %d\n").unwrap();
33     printf(fmt.as_ptr(), 10, 5);
34 }
35 # }
36 ```