this post was submitted on 25 Mar 2024
542 points (98.6% liked)

Programmer Humor

23431 readers
380 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] JATtho@sopuli.xyz 2 points 1 year ago
volatile int blackhole;
blackhole = 1;
const int X = blackhole;
const int Y = blackhole;

Compiler is forbidden to assume that X == 1 would be true. It's also forbidden to assume that X == Y. const just means the address and/or the data at the address is read only. const volatile int* const hwreg; -> "read only volatile value at read only address hwreg". Compiler can assume the hwreg address won't magically change, but can't assume the value read from that address won't.

[–] jadedwench@lemmy.world 4 points 1 year ago

laughs in evil PLC programmer A little forces enabled, a change here, and maybe just move this wire over there while I am at it...

[–] PriorityMotif@lemmy.world 9 points 1 year ago

Looks like they didn't want anybody using the secondary tank. Probably haven't had time to pull Dave's body out yet.

[–] Qwaffle_waffle@sh.itjust.works 3 points 1 year ago* (last edited 1 year ago)

This has 14 (Peter Cline) energy here for the photo. Keep the dials at zero!

[–] darkmogool@feddit.de 10 points 1 year ago (1 children)

Is this wrench made of chocolate?

[–] CptEnder@lemmy.world 8 points 1 year ago

Forbidden chocolate

[–] nothacking@discuss.tchncs.de 48 points 1 year ago (1 children)

This is actually how you should declare something that you will never change, but something might change externally, like an input pin or status register.

Writing to it might do something completely different or just crash, but you also don't want the compiler getting creative with reads; You don't want the compiler optimizing out a check for a button press because the "constant" value is never changed.

[–] sunbeam60@lemmy.one 4 points 1 year ago

Yeah I stumbled on this too. Surely the joke should be const mutable, not const volatile.

[–] Omega_Haxors@lemmy.ml 12 points 1 year ago* (last edited 1 year ago) (1 children)

Context is very interesting: https://stackoverflow.com/questions/4592762/difference-between-const-const-volatile

Const flags to the code that you cannot change the value, and volatile flags to the compiler that it's not safe to change the value.

[–] blackstrat@lemmy.fwgx.uk 4 points 1 year ago

Volatile means that the value should be read each time its accessed. It can't be cached in a register or the read be otherwise assumed and optimized away or the instructions around its access be reordered.

[–] Hobbes_Dent@lemmy.world 17 points 1 year ago* (last edited 1 year ago)

Just spin the pipe wrench open and slide it up then you can switch it back real quick.

Thank you for watching this OHSA message on bad lockout procedure, now back to your regularly scheduled programming.

load more comments