C Reference ยท ctype.h, math.h and others
C iso646.h: alternative operator spellings
Reference for iso646.h: the macros and, or, not, bitand, xor and friends that spell C operators with words, why they exist, and why C23 made them optional.
<iso646.h> defines eleven macros that spell operators with words: and for &&, or for ||, not for !, bitand for &, and so on. They were added in 1995 for programmers whose keyboards and character sets could not type symbols such as |, ~ or ^ (the ISO 646 national character sets replaced them with accented letters).
Today the header is rarely needed, but it is part of the standard library, it is harmless, and some people like the readability of if (a and not b). In C++ these words are real keywords and need no header, which is one reason C code that includes <iso646.h> ports easily.
#include <iso646.h> if (ready and not failed) { /* same as: ready && !failed */ }
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.
The macros
| Macro | Expands to | Operator |
|---|---|---|
and |
&& |
logical AND |
or |
|| |
logical OR |
not |
! |
logical NOT |
not_eq |
!= |
not equal |
bitand |
& |
bitwise AND (and address-of) |
bitor |
| |
bitwise OR |
xor |
^ |
bitwise XOR |
compl |
~ |
bitwise complement |
and_eq |
&= |
AND assignment |
or_eq |
|= |
OR assignment |
xor_eq |
^= |
XOR assignment |
Usage notes
- These are ordinary object-like macros, so they obey the same rules as the symbols they replace, including precedence and short-circuit evaluation:
a and f()does not callf()whenais zero. bitandalso stands for the unary address-of operator, sop = bitand x;meansp = &x;. It is legal but confusing; avoid it.- Because they are macros, you cannot use these names as identifiers once the header is included. A variable called
and,or,xorornotwould break, which matters in code that defines, say, a function namedxor. - The language also has digraphs (
<:for[,%:for#, and others) and, before C23, trigraphs such as??!for|. Trigraphs were removed in C23; digraphs andiso646.hremain. - C23: the header is unchanged, but most C style guides prefer the symbols, so match your project's conventions.
- In C++ the same words are keywords, so
<iso646.h>there is an empty compatibility header and<ciso646>was removed in C++20. - Do not mix styles within one expression.
a and b || ccompiles but is hard to read.