diff --git a/examples/bare4.rs b/examples/bare4.rs index 104c025dcec7ff20d925a8016701208d49bf4d76..9af31a0aeb035c6baf7ccce091ce3336b24fa090 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)] @@ -101,12 +101,14 @@ fn main() -> ! { // // What was the error message and explain why. // -// ** your answer here ** +// ** Compiler error E0133: "call to unsafe function is unsafe ..." +// Because read_volatile is defined as unsafe. ** // // 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 ** +// ** The section on safety reads that the behaviour is undefined if the parameter is not valid. +// The passed parameter must not be unaligned nor out of bounds. Undefined behaviour is unsafe! ** // // Commit your answers (bare4_2) //