]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_error_codes/src/error_codes/E0617.md
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / compiler / rustc_error_codes / src / error_codes / E0617.md
1 Attempted to pass an invalid type of variable into a variadic function.
2
3 Erroneous code example:
4
5 ```compile_fail,E0617
6 extern {
7 fn printf(c: *const i8, ...);
8 }
9
10 unsafe {
11 printf(::std::ptr::null(), 0f32);
12 // error: cannot pass an `f32` to variadic function, cast to `c_double`
13 }
14 ```
15
16 Certain Rust types must be cast before passing them to a variadic function,
17 because of arcane ABI rules dictated by the C standard. To fix the error,
18 cast the value to the type specified by the error message (which you may need
19 to import from `std::os::raw`).
20
21 In this case, `c_double` has the same size as `f64` so we can use it directly:
22
23 ```no_run
24 # extern {
25 # fn printf(c: *const i8, ...);
26 # }
27 unsafe {
28 printf(::std::ptr::null(), 0f64); // ok!
29 }
30 ```