DEV Community

BC
BC

Posted on

what is <iso646.h> in C standard library

#c

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        ^=
Enter fullscreen mode Exit fullscreen mode

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;
}
Enter fullscreen mode Exit fullscreen mode

Compile and run:

a < b
true 1
true 2
Enter fullscreen mode Exit fullscreen mode

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 -_-!!

Reference:

Top comments (1)

Collapse
 
bitecode profile image
BC

Ha, that’s interesting 🧐