Skip to content
Snippets Groups Projects
Commit a5dcb243 authored by August Svensson's avatar August Svensson
Browse files

bare0_5

parent 66a0a4b3
No related branches found
No related tags found
No related merge requests found
......@@ -28,17 +28,35 @@ static mut Y: u32 = 0;
#[entry]
fn main() -> ! {
// local mutable variable (changed in safe code)
let mut x = unsafe { X };
let mut x = read_x();
let mut x_tmp: u32;
loop {
x = x.wrapping_add(1u32);
// x += 1; // <- place breakpoint here (3)
unsafe {
X = X.wrapping_add(1u32);
// X += 1;
Y = X;
assert!(x == X && X == Y + 1);
// I assume that there was a point in not setting X = x directly since the assert is there;
// hence the x_tmp variable.
x_tmp = read_x();
x_tmp = x_tmp.wrapping_add(1u32);
write_x(x_tmp);
write_y(read_x());
}
}
fn write_x(x: u32) {
unsafe { X = x; }
}
fn write_y(y: u32) {
unsafe { Y = y; }
}
fn read_x() -> u32 {
unsafe { X }
}
fn read_y() -> u32 {
unsafe { Y }
}
// 0. Compile/build the example in debug (dev) mode.
......@@ -88,7 +106,7 @@ fn main() -> ! {
//
// 4. Change the assertion to `assert!(x == X && X == Y + 1)`, what happens?
//
// ** place your answer here **
// * The program enters a panic loop.
//
// Commit your answers (bare0_4)
//
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment