Skip to content

Commit 55a3f99

Browse files
authored
Merge pull request #736 from oli-obk/master
Elaborate on how to use an extern static correctly
2 parents e115753 + 18d7140 commit 55a3f99

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/items/external-blocks.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Two kind of item _declarations_ are allowed in external blocks: [functions] and
3838
[statics]. Calling functions or accessing statics that are declared in external
3939
blocks is only allowed in an `unsafe` context.
4040

41+
## Functions
42+
4143
Functions within external blocks are declared in the same way as other Rust
4244
functions, with the exception that they may not have a body and are instead
4345
terminated by a semicolon. Patterns are not allowed in parameters, only
@@ -53,10 +55,18 @@ extern "abi" for<'l1, ..., 'lm> fn(A1, ..., An) -> R`, where `'l1`, ... `'lm`
5355
are its lifetime parameters, `A1`, ..., `An` are the declared types of its
5456
parameters and `R` is the declared return type.
5557

56-
Statics within external blocks are declared in the same way as statics outside of external blocks,
58+
## Statics
59+
60+
Statics within external blocks are declared in the same way as [statics] outside of external blocks,
5761
except that they do not have an expression initializing their value.
5862
It is `unsafe` to access a static item declared in an extern block, whether or
59-
not it's mutable.
63+
not it's mutable, because there is nothing guaranteeing that the bit pattern at the static's
64+
memory is valid for the type it is declared with, since some arbitrary (e.g. C) code is in charge
65+
of initializing the static.
66+
67+
Extern statics can be either immutable or mutable just like [statics] outside of external blocks.
68+
An immutable static *must* be initialized before any Rust code is executed. It is not enough for
69+
the static to be initialized before Rust code reads from it.
6070

6171
## ABI
6272

0 commit comments

Comments
 (0)