this post was submitted on 22 Jul 2025
407 points (98.1% liked)

Programmer Humor

25282 readers
743 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
 

I don't think that casting a range of bits as some other arbitrary type "is a bug nobody sees coming".

C++ compilers also warn you that this is likely an issue and will fail to compile if configured to do so. But it will let you do it if you really want to.

That's why I love C++

you are viewing a single comment's thread
view the rest of the comments
[โ€“] wer2@lemmy.zip 30 points 4 days ago (1 children)

My issue is C++ will "let me do it", and by that I mean "you didn't cast here (which is UB), so I will optimize out a null check later, and then segfault in a random location"

[โ€“] vivendi@programming.dev 5 points 4 days ago* (last edited 4 days ago)

Always check your programs on -O0 or pay the price

Shit gets really fun when you find out your code is a edge case for compiler optimization and should never be optimized away (although this is very very rare for -O2)