From 8a1f801e7806b30e9df2ebec706c97b8e60f0d9c Mon Sep 17 00:00:00 2001 From: "henthe-5@student.ltu.se" <henthe-5@student.ltu.se> Date: Fri, 22 Feb 2019 08:13:03 +0100 Subject: [PATCH] bare4_2 --- examples/bare4.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/bare4.rs b/examples/bare4.rs index bdfd2f7..81f7d26 100644 --- a/examples/bare4.rs +++ b/examples/bare4.rs @@ -39,8 +39,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)] @@ -108,12 +108,14 @@ fn main() -> ! { // // What was the error message and explain why. // -// ** your answer here ** +// ** "call to unsafe function is unsafe and requires unsafe function or block" +// The read_volatile takes a raw pointer as parameter, dereferencing a raw pointer is always considered 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 ** +// ** It's not certain that the memory address is readable or that the memory is aligned thus may result in undefined behavior ** // // Commit your answers (bare4_2) // -- GitLab