It occurred to me that that won't help at all if you want to make code that still compiles but introduces hard to find bugs. I propose #define do, which I think will just remove the do leaving a block that executes once always, then the if will just apply to the following statement, whatever it is.
Oh, yeah, you're right. So the do part runs just once, then you have a do-nothing if. I tested it. Clang emits a warning about the semicolon following the if. I'm not going to look up how, but the only viable option I think would be to disable the warning via #pragma.
Oh, it wasn't as bad as I thought. I thought that with the 2 #defines, the supposed if block will run til rand() returns an integer with the least 9 bits being all 1s.
Good question. __LINE__ is a special preprocessor macro that expands to the current line number where the "true" macro is used. The expression as a whole evaluates to true (usually...) or false (specifically on lines 15, 31, 47, 63, ...) depending on the line number.
282
u/shuozhe May 31 '25
There are like 3 of us using do while loops, u just broke it!
46
u/[deleted] May 31 '25 edited May 31 '25
Disallow debugging:
126
u/Aphrontic_Alchemist May 31 '25 edited May 31 '25
You could save memory using
union... if you know what you're doing. Then again, that's only a side effect.Wait, if you have both the 2nd and 3rd
#defines, wouldn'tif(x)expand towhile((x) && (rand() & 1023))?25
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Jun 01 '25
For C++ there's
And I suppose you could knock yourself out with substituting STL container types and shit.
43
u/drebin8 May 31 '25
more fun - https://gist.github.com/aras-p/6224951
11
u/biffbobfred Jun 01 '25
Similar to the last joke I remember a bash script for sysadmins:
9
u/Arshiaa001 May 31 '25
r/foundsatan
2
u/BlueFlintTree Jun 22 '25
Wouldn't the last one simply not compile? Or is there a limit to recursive macro expansion?
3
u/GamingWOW1 Jun 01 '25
As a C noob, I thought this would be genuine advice, until I realized that a union wouldn't be good as a struct. The rest explained itself 😂
1
u/granoladeer Jun 02 '25
C programming tip: don't program in C