From ee56513f4c7d9c4be75c10a93a77aa2b75bac9a8 Mon Sep 17 00:00:00 2001 From: DevDoggo <devdoggo@protonmail.com> Date: Wed, 23 May 2018 00:52:44 +0200 Subject: [PATCH] Done --- examples/bare4.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/bare4.rs b/examples/bare4.rs index 4861ecd..66090d8 100644 --- a/examples/bare4.rs +++ b/examples/bare4.rs @@ -27,8 +27,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)] @@ -101,10 +101,15 @@ fn main() { // 2. comment out line 30 and uncomment line 31 (essentially omitting the `unsafe`) // what was the error message and explain why, // +// >> Call to unsafe function requires unsafe function or block // ** your answer here ** // // 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 ) +// +// >> While volatile will not be re-ordered by the compiler, +// this still doesn't prevent something to start changing the value +// as the program may try to read (since read may not be an atomic operation) // ** your answer here ** // // commit your answers (bare4_2) -- GitLab