Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add the c_variadic language feature - Add the c_variadic library feature
- Loading branch information
1 parent
210c607
commit 1a6e9e2
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# `c_variadic` | ||
|
||
The tracking issue for this feature is: [#44930] | ||
|
||
[#44930]: https://github.com/rust-lang/rust/issues/44930 | ||
|
||
------------------------ | ||
|
||
The `c_variadic` language feature enables C-variadic functions to be | ||
defined in Rust. The may be called both from within Rust and via FFI. | ||
|
||
## Examples | ||
|
||
```rust | ||
#![feature(c_variadic)] | ||
|
||
pub unsafe extern "C" fn add(n: usize, mut args: ...) -> usize { | ||
let mut sum = 0; | ||
for _ in 0..n { | ||
sum += args.arg::<usize>(); | ||
} | ||
sum | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# `c_variadic` | ||
|
||
The tracking issue for this feature is: [#44930] | ||
|
||
[#44930]: https://github.com/rust-lang/rust/issues/44930 | ||
|
||
------------------------ | ||
|
||
The `c_variadic` library feature exposes the `VaList` structure, | ||
Rust's analogue of C's `va_list` type. | ||
|
||
## Examples | ||
|
||
```rust | ||
#![feature(c_variadic)] | ||
|
||
use std::ffi::VaList; | ||
|
||
pub unsafe extern "C" fn vadd(n: usize, mut args: VaList) -> usize { | ||
let mut sum = 0; | ||
for _ in 0..n { | ||
sum += args.arg::<usize>(); | ||
} | ||
sum | ||
} | ||
``` |