Search code examples
ctokencompatibilitybitwise-operatorslogical-operators

When do I need to use the alternative macros for bitwise and logical operators inside the header file of iso646.h?


I know that in the header of iso646.h, the following eleven marco constants are defined to provide alternative descriptions of the bitwise and logical operators:

and is a macro for &&.

and_eq is a macro for &=.

bitand is a macro for &.

bitor is a macro for |.

compl is a macro for ~.

not is a macro for !.

not_eq is a macro for !=.

or is a macro for ||.

or_eq is a macro for |=

xor is a macro for ^.

xor_eq is a macro for ^=.


But when do I need to use these alternative macros?

  • Under which circumstances do I need to use the alternative macros for bitwise and logical operators inside of the header file of iso646.h?

Solution

  • You should use it if your encoding does not implement the full ASCII repertoire:

    C derived its repertoire from the ASCII codeset. Unfortunately the ASCII repertoire is not a subset of all other commonly used character sets, and widespread practice in Europe is not to implement all of ASCII either, but use some parts of its collating sequence for special national characters.

    The solution is an internationally agreed-upon repertoire, in terms of which an international representation of C can be defined. The ISO has defined such a standard: ISO 646 describes an invariant subset of ASCII.

    The characters in the ASCII repertoire used by C and absent from the ISO 646 repertoire are:

        # [ ] { } \ | ~ ^
    

    Taken from the ANSI C Rationale, [2.2.1.1 Trigraph sequences]

    As pointed out by @chqrlie, this was an important issue to take into consideration in the 1980s but much less relevant today.

    This is also the reason trigraphs were introduced (explained further along in the same section). As such when a non-ASCII encoding is used, the macros are replaced by their trigraph versions in iso646.h.