#[entry]
Expand description
Attribute to declare the entry point of the program
The specified function will be called by the reset handler after RAM has been initialized. In
the case of the thumbv7em-none-eabihf
target the FPU will also be enabled before the function
is called.
The type of the specified function must be [unsafe] fn() -> !
(never ending function)
§Properties
The entry point will be called by the reset handler. The program can’t reference to the entry point, much less invoke it.
static mut
variables declared within the entry point are safe to access. The compiler can’t
prove this is safe so the attribute will help by making a transformation to the source code: for
this reason a variable like static mut FOO: u32
will become let FOO: &'static mut u32;
. Note
that &'static mut
references have move semantics.
§Examples
- Simple entry point
#[entry]
fn main() -> ! {
loop {
/* .. */
}
}
static mut
variables local to the entry point are safe to modify.
#[entry]
fn main() -> ! {
static mut FOO: u32 = 0;
let foo: &'static mut u32 = FOO;
assert_eq!(*foo, 0);
*foo = 1;
assert_eq!(*foo, 1);
loop {
/* .. */
}
}