Skip to content

Commit 1a6e9e2

Browse files
committed
Add c_variadic to the unstable-book
- Add the c_variadic language feature - Add the c_variadic library feature
1 parent 210c607 commit 1a6e9e2

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# `c_variadic`
2+
3+
The tracking issue for this feature is: [#44930]
4+
5+
[#44930]: https://github.com/rust-lang/rust/issues/44930
6+
7+
------------------------
8+
9+
The `c_variadic` language feature enables C-variadic functions to be
10+
defined in Rust. The may be called both from within Rust and via FFI.
11+
12+
## Examples
13+
14+
```rust
15+
#![feature(c_variadic)]
16+
17+
pub unsafe extern "C" fn add(n: usize, mut args: ...) -> usize {
18+
let mut sum = 0;
19+
for _ in 0..n {
20+
sum += args.arg::<usize>();
21+
}
22+
sum
23+
}
24+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# `c_variadic`
2+
3+
The tracking issue for this feature is: [#44930]
4+
5+
[#44930]: https://github.com/rust-lang/rust/issues/44930
6+
7+
------------------------
8+
9+
The `c_variadic` library feature exposes the `VaList` structure,
10+
Rust's analogue of C's `va_list` type.
11+
12+
## Examples
13+
14+
```rust
15+
#![feature(c_variadic)]
16+
17+
use std::ffi::VaList;
18+
19+
pub unsafe extern "C" fn vadd(n: usize, mut args: VaList) -> usize {
20+
let mut sum = 0;
21+
for _ in 0..n {
22+
sum += args.arg::<usize>();
23+
}
24+
sum
25+
}
26+
```

0 commit comments

Comments
 (0)