The Genesis of 'and' and 'or' as Alternative Tokens in C
C developers are familiar with the logical operators '&&' (logical AND) and '||' (logical OR) as indispensable tools for conditional statements and expressions. However, there exist alternative tokens, 'and' and 'or,' offering identical functionality. When and how did these tokens enter the C lexicon?
Birth of the Alternative Tokens
Contrary to the assumption that they are recent additions, the alternative tokens 'and' and 'or' have been a part of the C standard since its inception with ISO C 98. This is documented in section 2.5/ Alternative tokens [lex.digraph] of the standard:
Alternative token representations are provided for some operators and punctuators.
This implies that in all aspects of the language, each alternative token behaves identically to its primary token except for its spelling. A comprehensive list of these tokens can be found in Table 2 of the standard:
Alternative Token | Primary Token | ||
---|---|---|---|
and | && | ||
or |
Usage and Rarity
Despite their inclusion in the standard, the alternative tokens 'and' and 'or' have not gained widespread adoption. The primary reason lies in their intended use case, which was primarily to cater to environments with limited character sets. For instance, the baseline EBCDIC character set on older IBM mainframes lacked certain characters, including square brackets '[', making the alternative tokens a viable solution.
Conclusion
While unfamiliar to many C developers, the alternative tokens 'and' and 'or' have been a part of the standard for over two decades. Their existence serves as a testament to the language's flexibility in accommodating diverse usage scenarios. However, given their niche application, these tokens remain obscure to the majority of C practitioners.
The above is the detailed content of Why Are 'and' and 'or' Alternative Tokens in C ?. For more information, please follow other related articles on the PHP Chinese website!