3 ms·
#define while if
by marginalia_nu 5y ago
#define while if
- toxik 5y agoPerfect balance of harmless and annoying. I would probably never figure it out. Maybe include a cryptic warning so the person eventually looks at it… #define while if #warning "loop flow control substituted for conditional"
- layer8 5y agoThat fails if you have a do ... while.
- toxik 5y agoMay I then suggest... #define if while
- layer8 5y agoThat fails when you have an else. :)
- Akronymus 5y agowould that work? #define while(x) for(;true;)
- layer8 5y agoIt would cause a compile error for do-while loops. And there’s no reason to use `for` here, `while (true)` would do the same (C macros don’t expand recursively in such cases).
- Akronymus 5y agoI guess i would go with this in a header file that includes rand.h instead, then: #define while(cond) while ((cond) && rand() >= somesufficientlysmallnumber)
- toxik 5y ago#define else There!
- layer8 5y agoI think I could devise scenarios where that would fail compilation when `else` is used as a macro argument, but other than that it seems quite solid. :)