Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
e7020e_2020
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tom Hammarkvist
e7020e_2020
Commits
6013c372
Commit
6013c372
authored
5 years ago
by
Hammarkvast
Browse files
Options
Downloads
Patches
Plain Diff
bare4_2
parent
c7f0154f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/bare4.rs
+8
-2
8 additions, 2 deletions
examples/bare4.rs
with
8 additions
and
2 deletions
examples/bare4.rs
+
8
−
2
View file @
6013c372
...
...
@@ -36,8 +36,8 @@ use address::*;
#[inline(always)]
fn
read_u32
(
addr
:
u32
)
->
u32
{
unsafe
{
core
::
ptr
::
read_volatile
(
addr
as
*
const
_
)
}
//
core::ptr::read_volatile(addr as *const _)
//
unsafe { core::ptr::read_volatile(addr as *const _) }
core
::
ptr
::
read_volatile
(
addr
as
*
const
_
)
}
#[inline(always)]
...
...
@@ -104,12 +104,18 @@ fn main() -> ! {
// What was the error message and explain why.
//
// ** your answer here **
// error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
// read_volatile is an unsafe function, which requires it to be called under a unsafe block.
//
// Digging a bit deeper, why do you think `read_volatile` is declared `unsafe`.
// (https://doc.rust-lang.org/core/ptr/fn.read_volatile.html, for some food for thought )
//
// ** your answer here **
//
// read_volatile is inherently unsafe because reading a volatile variable is, indeed volatile
// A volatile variable is volatile because it moves the value out of the address without
// preventing further usage of that specific address.
//
// Commit your answers (bare4_2)
//
// 3. Volatile read/writes are explicit *volatile operations* in Rust, while in C they
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment