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

Programmer Humor

19476 readers
199 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 1 year ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 2 points 7 months 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.

[–] [email protected] 4 points 7 months 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...

[–] [email protected] 9 points 7 months ago

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

[–] [email protected] 3 points 7 months ago* (last edited 7 months ago)

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

[–] [email protected] 10 points 7 months ago (1 children)

Is this wrench made of chocolate?

[–] [email protected] 8 points 7 months ago

Forbidden chocolate

[–] [email protected] 48 points 7 months 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.

[–] [email protected] 4 points 7 months ago

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

[–] [email protected] 12 points 7 months ago* (last edited 7 months 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.

[–] [email protected] 4 points 7 months 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.

[–] [email protected] 17 points 7 months ago* (last edited 7 months 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
view more: next ›