Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Note on transformation of static variables by attribute exception #251

Merged
merged 5 commits into from
Jul 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/start/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This behavior is pretty much intended and it's required to provide a feature:
fn SysTick() {
static mut COUNT: u32 = 0;
// `COUNT` has type `&mut u32` and it's safe to use
// `COUNT` has transformed to type `&mut u32` and it's safe to use
*COUNT += 1;
}
```
Expand All @@ -47,6 +47,12 @@ use `static mut` variables. How is this possible? This is possible because
`exception` handlers can *not* be called by software thus reentrancy is not
possible.

> Note that the `exception` attribute transforms definitions of static variables
> inside the function by wrapping them into `unsafe` blocks and providing us
> with new appropriate variables of type `&mut` of the same name.
> Thus we can derefence the reference via `*` to access the values of the variables without
> needing to wrap them in an `unsafe` block.
## A complete example

Here's an example that uses the system timer to raise a `SysTick` exception
Expand Down