Skip to content
Snippets Groups Projects
Commit 6013c372 authored by Hammarkvast's avatar Hammarkvast
Browse files

bare4_2

parent c7f0154f
Branches
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment