From 6013c37280fb0d52a41daa076d252d49b3c10a72 Mon Sep 17 00:00:00 2001 From: Hammarkvast <tomham-3@student.ltu.se> Date: Wed, 8 Apr 2020 12:09:36 +0200 Subject: [PATCH] bare4_2 --- examples/bare4.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/bare4.rs b/examples/bare4.rs index 839d1e8..6628884 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 -- GitLab