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

196

16511 readers
2963 users here now

Be sure to follow the rule before you head out.

Rule: You must post before you leave.

^other^ ^rules^

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] bi_tux@lemmy.world 4 points 1 month ago (1 children)
[–] zea_64@lemmy.blahaj.zone 6 points 1 month ago (1 children)

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

[–] bi_tux@lemmy.world 3 points 1 month ago* (last edited 1 month ago) (1 children)

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 month 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)