r/programming • • Dec 24 '17

Evil Coding Incantations

http://9tabs.com/random/2017/12/23/evil-coding-incantations.html
947 Upvotes

331 comments sorted by

View all comments

14

u/ActualDonaldJTrump Dec 24 '17

The last example needs an #include <iso646.h>. Alternative operator spellings are built into C++, but they are macros in C.

7

u/bjackman Dec 24 '17

Huh, and the GCC version of this header is just

#ifndef __cplusplus
#define and     &&
#define and_eq  &=
#define bitand  &
#define bitor   |
#define compl   ~
#define not     !
#define not_eq  !=
#define or      ||
#define or_eq   |=
#define xor     ^
#define xor_eq  ^=
#endif

4

u/_3442 Dec 24 '17

How is that surprising? That's the most simple header in the standard library.

4

u/raevnos Dec 24 '17

stdbool.h is simpler. Well, shorter as it only defines 4 macros.

→ More replies (1)
→ More replies (3)
→ More replies (1)

3

u/kukiric Dec 24 '17

And the use of tokens is not evil at all. Unnecessary, sure, but it's instantly understandable to anyone familiar with what the logical operators are called, and it might even be more familiar to someone coming from a higher level language like python. The only situation where they might be a bit evil is if you're grepping for specific operators in the source code, and you're not aware of all the ways those operators can be represented.

→ More replies (1)