Skip to content

Commit

Permalink
auto merge of #13451 : cmr/rust/doc-ffi, r=brson
Browse files Browse the repository at this point in the history
Closes #8748
  • Loading branch information
bors committed Apr 11, 2014
2 parents cea8def + eabf78c commit 9ff0811
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/doc/guide-ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,16 @@ NUL-terminated string for interoperability with C, you should use the `c_str::to

The standard library includes type aliases and function definitions for the C standard library in
the `libc` module, and Rust links against `libc` and `libm` by default.

# The "nullable pointer optimization"

Certain types are defined to not be `null`. This includes references (`&T`,
`&mut T`), owning pointers (`~T`), and function pointers (`extern "abi"
fn()`). When interfacing with C, pointers that might be null are often used.
As a special case, a generic `enum` that contains exactly two variants, one of
which contains no data and the other containing a single field, is eligible
for the "nullable pointer optimization". When such an enum is instantiated
with one of the non-nullable types, it is represented as a single pointer,
and the non-data variant is represented as the null pointer. So
`Option<extern "C" fn(c_int) -> c_int>` is how one represents a nullable
function pointer using the C ABI.

0 comments on commit 9ff0811

Please sign in to comment.