]>
Commit | Line | Data |
---|---|---|
487cf647 FG |
1 | Static variables with the `#[linkage]` attribute within external blocks |
2 | must have one of the following types, which are equivalent to a nullable | |
3 | pointer in C: | |
4 | ||
5 | * `*mut T` or `*const T`, where `T` may be any type. | |
6 | ||
7 | * An enumerator type with no `#[repr]` attribute and with two variants, where | |
8 | one of the variants has no fields, and the other has a single field of one of | |
9 | the following non-nullable types: | |
10 | * Reference type | |
11 | * Function pointer type | |
12 | ||
13 | The variants can appear in either order. | |
14 | ||
15 | For example, the following declaration is invalid: | |
16 | ||
17 | ```compile_fail,E0791 | |
18 | #![feature(linkage)] | |
19 | ||
20 | extern "C" { | |
21 | #[linkage = "extern_weak"] | |
22 | static foo: i8; | |
23 | } | |
24 | ``` | |
25 | ||
26 | The following declarations are valid: | |
27 | ||
28 | ``` | |
29 | #![feature(linkage)] | |
30 | ||
31 | extern "C" { | |
32 | #[linkage = "extern_weak"] | |
33 | static foo: Option<unsafe extern "C" fn()>; | |
34 | ||
35 | #[linkage = "extern_weak"] | |
36 | static bar: Option<&'static i8>; | |
37 | ||
38 | #[linkage = "extern_weak"] | |
39 | static baz: *mut i8; | |
40 | } | |
41 | ``` |