you are viewing a single comment's thread
view the rest of the comments
[–] 14 points 2 years ago* (last edited 2 years ago) (7 children)

RWIIR!!!

edit: here, I did it for you:

use std::*;

static mut sucked: bool = false;

fn main() {
        unsafe {
                check_sucked();
        }
        println!("Kris has been sucked is {}", sucked)
}

unsafe fn check_sucked() {
        if !sucked {
                suck();
        }
}

fn suck() {
        sucked = true;
}

edit 2: fixed it

  • source
  • hideshow 7 child comments
  • [–] 12 points 2 years ago (4 children)
  • [–] 4 points 2 years ago (3 children)
  • [–] 6 points 2 years ago (2 children)

    If you made it static, sure, but right now you're living compiler error

  • source
  • parent
  • hideshow 2 child comments
  • [–] 3 points 2 years ago* (1 child)

    oh well, I'm just starting to learn the language and come from java, so I thought: wait, it can't be static

  • source
  • parent
  • hideshow 1 child comment
  • [–] 3 points 2 years ago

    const is more like C++ constexpr, but static is similar to static from C: it's a variable that lives outside any scope. Of course, that means the same static can be accessed by multiple threads, so writing to a static is unsafe (except for types like Mutex, you can safely use those to write, but your static won't be declared mut)

  • source
  • parent