I was reading some materials about C standard library, just found this file iso646.h
, unlike other header files like math.h
, stdio.h
, this header file's name is not that obvious to tell what it is.
You can see its full content here, the essential part is just:
#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 ^=
Those are just simple macros and they are interesting: with this header file, we can write some code like Python if (a and b)
, if (a or b)
, if (not a)
:
#include <stdio.h>
#include <iso646.h>
int main() {
int a = 1, b = 2;
int x = 3, y = 4;
if (not a < b) {
puts("a < b");
} else {
puts("not a < b");
}
if (a < b or x > y) {
puts("true 1");
} else {
puts("false 1");
}
if (a < b and x < y) {
puts("true 2");
} else {
puts("false 2");
}
return 0;
}
Compile and run:
a < b
true 1
true 2
And actually this file iso646.h
has been in C standard for a long time:
... After a long period of stability, three new header files (iso646.h, wchar.h, and wctype.h) were added with Normative Addendum 1 (NA1), an addition to the C Standard ratified in 1995 ...
Apparently it has been there for more than 20 years, and I just learned it today -_-!!
Top comments (1)
Ha, that’s interesting 🧐