209
Deltarule (lemmy.world)
you are viewing a single comment's thread
view the rest of the comments
[-] bi_tux@lemmy.world 14 points 1 year ago* (last edited 1 year ago)

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

[-] RacoonVegetable@reddthat.com 19 points 1 year ago

use std

Oh no….

[-] zea_64@lemmy.blahaj.zone 12 points 1 year ago
[-] bi_tux@lemmy.world 4 points 1 year ago
[-] zea_64@lemmy.blahaj.zone 6 points 1 year ago

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

[-] bi_tux@lemmy.world 3 points 1 year ago* (last edited 1 year ago)

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

[-] zea_64@lemmy.blahaj.zone 3 points 1 year 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)

[-] Smorty@lemmy.blahaj.zone 3 points 1 year ago

I personally would have matched the sucked... Maybe printed some lovely message about being content or somezhin

this post was submitted on 02 Oct 2024
209 points (98.2% liked)

196

19101 readers
357 users here now

Be sure to follow the rule before you head out.


Rule: You must post before you leave.



Other rules

Behavior rules:

Posting rules:

NSFW: NSFW content is permitted but it must be tagged and have content warnings. Anything that doesn't adhere to this will be removed. Content warnings should be added like: [penis], [explicit description of sex]. Non-sexualized breasts of any gender are not considered inappropriate and therefore do not need to be blurred/tagged.

If you have any questions, feel free to contact us on our matrix channel or email.

Other 196's:

founded 2 years ago
MODERATORS