diff --git a/examples/bare4.rs b/examples/bare4.rs index 839d1e888f2cef061f99a88776a502a3539a8974..66288840c1506b18508902c3f39ffbd44a006569 100644 --- a/examples/bare4.rs +++ b/examples/bare4.rs @@ -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