]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_error_codes/src/error_codes/E0060.md
New upstream version 1.63.0+dfsg1
[rustc.git] / compiler / rustc_error_codes / src / error_codes / E0060.md
CommitLineData
60c5eb7d
XL
1External C functions are allowed to be variadic. However, a variadic function
2takes a minimum number of arguments. For example, consider C's variadic `printf`
3function:
4
f9f354fc 5```compile_fail,E0060
60c5eb7d
XL
6use std::os::raw::{c_char, c_int};
7
8extern "C" {
9 fn printf(_: *const c_char, ...) -> c_int;
10}
f9f354fc
XL
11
12unsafe { printf(); } // error!
60c5eb7d
XL
13```
14
15Using this declaration, it must be called with at least one argument, so
16simply calling `printf()` is invalid. But the following uses are allowed:
17
18```
60c5eb7d
XL
19# use std::os::raw::{c_char, c_int};
20# #[cfg_attr(all(windows, target_env = "msvc"),
923072b8
FG
21# link(name = "legacy_stdio_definitions",
22# kind = "static", modifiers = "-bundle"))]
60c5eb7d
XL
23# extern "C" { fn printf(_: *const c_char, ...) -> c_int; }
24# fn main() {
25unsafe {
26 use std::ffi::CString;
27
28 let fmt = CString::new("test\n").unwrap();
29 printf(fmt.as_ptr());
30
31 let fmt = CString::new("number = %d\n").unwrap();
32 printf(fmt.as_ptr(), 3);
33
34 let fmt = CString::new("%d, %d\n").unwrap();
35 printf(fmt.as_ptr(), 10, 5);
36}
37# }
38```