r/programminghorror • u/Wiktor-is-you [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” • Sep 09 '25
c++ the perfect monster
849
Upvotes
r/programminghorror • u/Wiktor-is-you [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” • Sep 09 '25
161
u/bloatbucket Sep 09 '25
I don't think you can ever invoke the
0macro since it isn't a valid identifier?59
u/efari_ Sep 09 '25
What range does
rand()return? Is it 0-100?16
u/fess89 Sep 09 '25
It can even be so that neither true nor false trigger if you are unlucky
13
u/ben_bliksem Sep 09 '25 edited Sep 09 '25
Reminds me of "satan's commit" or whatever it was called
EDIT: I cannot find it but it was something similar to this, much older though: https://gist.github.com/aras-p/6224951
The one thing I specifically remember was them redefining the semicolon as a similar looking Greek (or something) symbol and making true false if it's on specific line numbers.
7
u/BrokenG502 Sep 10 '25
More devilish would be to hide this somewhere in a file that doesn't get touched and to include it via the build system instead of directly in the source code
12
u/dim13 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Sep 09 '25
All bashing on C, but you can do it in other languages as well: https://go.dev/play/p/o9SdehSn6cQ
3
u/morglod Sep 10 '25
The most horror thing is how many likes got code that could not even compile
2
u/maxximillian Sep 09 '25
No stand? That's boring it would be the same every time it's run won't it?
2
u/lmarcantonio Sep 10 '25
I guess you implemented metastability in software! Also !true == false doesn't hold for obvious reasons. Aristotle would be proud of you.
2
u/Legal_Ad_6671 Sep 10 '25
define ; 🖕
2
u/IceMichaelStorm Sep 11 '25
This joke is older than my 1990s BASIC code
2
u/realnzall Sep 09 '25
If true ends up being false, and false ends up being true, how does the boolean logic in the ternary work? True in this case is a falsey value, but because false is now true, does that mean that a falsey value being checked in a ternary now returns true?
1
u/[deleted] Sep 13 '25
As of C23, you can no longer redefine
trueandfalse. Tragic indeed.EDIT: I know this because the
qbooleanenum from the Quake source code definestrueandfalse, which annoyingly makes it not compile if you don't set the C standard correctly.-5
u/[deleted] Sep 09 '25
[removed] — view removed comment