Skip to content

Commit

Permalink
Add c_variadic to the unstable-book
Browse files Browse the repository at this point in the history
 - Add the c_variadic language feature
 - Add the c_variadic library feature
  • Loading branch information
dlrobertson committed Feb 27, 2019
1 parent 210c607 commit 1a6e9e2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/doc/unstable-book/src/language-features/c-variadic.md
@@ -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
}
```
26 changes: 26 additions & 0 deletions src/doc/unstable-book/src/library-features/c-variadic.md
@@ -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
}
```

0 comments on commit 1a6e9e2

Please sign in to comment.