<iso646.h> defines readable macro spellings for operators that use symbols: and for &&, or for ||, not for !, bitand for &, and so on.
It was added in 1995 so programs could be typed on keyboards that lack characters such as &, |, ~, and ^. Today it is mostly a style choice.
Remember
#include <iso646.h>
and && bitand & and_eq &=
or || bitor | or_eq |=
not ! xor ^ xor_eq ^=
not_eq != compl ~
Use
Prefer
Logical operators
and, or, not
Bitwise operators
bitand, bitor, xor, compl
Compound assignment
and_eq, or_eq, xor_eq
Comparison
not_eq
Approach
How to Use iso646.h in C
Include the header and swap the symbol for the word. Meaning and precedence do not change.
Add #include <iso646.h>.
Replace a symbol with its word: && becomes and.
Remember the macros expand to the same tokens, so precedence is unchanged.
Do not use these words as variable or function names.
Pick one style (symbols or words) for a whole project.
Piece
Required?
Role
#include <iso646.h>
Yes
Defines the eleven macros
The operator word
Yes
A plain preprocessor macro in C (a keyword in C++)
Linker flags
No
Nothing to link
Pseudocode
Pseudocode
if (a > 0 and b > 0) -> if (a > 0 && b > 0)
if (not done) -> if (!done)
flags or_eq MASK -> flags |= MASK
mask = compl x bitand 0xFF -> mask = ~x & 0xFF
Reference
Cheat Sheet
The complete list of eleven alternative spellings.
Name
Meaning
and
&&
and_eq
&=
bitand
&
bitor
|
compl
~
not
!
not_eq
!=
or
||
or_eq
|=
xor
^
xor_eq
^=
Trace
Worked Walkthrough — Words Become Symbols
Trace what each spelling expands to for a = 5, b = -2, and two bytes.
Calculation
int a = 5, b = -2;
a > 0 and b > 0 -> 1 && 0 -> false
a > 0 or b > 0 -> 1 || 0 -> true
not (a == b) -> !(0) -> true
0xF0 bitand 0x3C -> 0xF0 & 0x3C = 0x30
0xF0 bitor 0x3C -> 0xF0 | 0x3C = 0xFC
0xF0 xor 0x3C -> 0xF0 ^ 0x3C = 0xCC
Code
C Examples
Compile with gcc file.c -std=c11 -o out.
Example 1 — Logical Operators as Words
Rewrite &&, ||, and ! with and, or, and not.
C
#include <iso646.h>
#include <stdio.h>
int main(void) {
int a = 5;
int b = -2;
if (a > 0 and b > 0) {
printf("both positive\n");
} else {
printf("not both positive\n");
}
if (a > 0 or b > 0) {
printf("at least one positive\n");
}
if (not (a == b)) {
printf("a and b differ\n");
}
return 0;
}
Output
not both positive
at least one positive
a and b differ
How It Works
and.a > 0 and b > 0 is false because b is negative.
or.a > 0 or b > 0 is true because a is positive.
not.not (a == b) is !(a == b), true because they differ.
Example 2 — Bitwise Operators as Words
Use bitand, bitor, xor, and compl on two bytes.
C
#include <iso646.h>
#include <stdio.h>
int main(void) {
unsigned x = 0xF0;
unsigned y = 0x3C;
printf("AND = %02X\n", x bitand y);
printf("OR = %02X\n", x bitor y);
printf("XOR = %02X\n", x xor y);
printf("NOT = %02X\n", (compl x) bitand 0xFFu);
return 0;
}