1

I've come across the iso646.h which provides some of the nice logical keyword operators that I'm used to from python. Is one of the following approaches preferred over the other?

if (x>7 && y<-2)
    printf("Normal symbols\n");
#include<iso646.h>
if (x > 7 and z < 4)
     printf("Iso646 is here\n");

Is there ever a place where one form would be preferred over the other? Or is this like the bool type which is a nice way to replace doing int is_valid=1; ?

6
  • 3
    Most people don't bother with the names from <iso646.h>. C++ has the names built-in as keywords. I believe it was added to C for compatibility (or maybe C++ added them for compatibility with C). The ! operator may be awkward on some EBCDIC (IBM mainframe) systems. However, there's no major downside to using them other than their unfamiliarity to the average C coder. Commented Jan 25, 2021 at 6:59
  • From Alternative operators and tokens: "To be able to use character encodings where some or all of these symbols do not exist". No good reason to use them, unless you expect your source code to be converted to some unusual encoding that does not cover the ASCII set. Commented Jan 25, 2021 at 7:00
  • 1
    See the C99 Rationale for more information. Search for either iso646.h or MSE.4 to find the information. Commented Jan 25, 2021 at 7:05
  • 1
    The bool type (from <stdbool.h>, along with true and false) is more widely used (by far) than the <iso646.h> alternative operator names. Note that the alternative spellings are addressing the same problem that trigraphs and digraphs also address — that C uses a wide vocabulary of punctuation symbols, and some of those symbols are not available in some codesets for non-American languages. Commented Jan 25, 2021 at 7:10
  • 3
    note that the bool type is not merely a nice way to replace int is_valid = 1; - it behaves completely differently from any other integer type w.r.t. value conversion! The bool is_valid = something; would be more analogous to int is_valid = !!(something); - or int is_valid = not not (something); to keep the theme of the question Commented Jan 25, 2021 at 7:25

2 Answers 2

3

As a C developer, I would be puzzled if I see and instead of &&. Or should it be a single &? I would need to dig into the include files to be sure how that uncommon keyword is defined.

Indeed && is much more familiar than and in the context of a C program.

Sign up to request clarification or add additional context in comments.

Comments

1

Very few are aware that iso646.h even exists, so therefore it is a bad idea to use it. C programmers are simply not used to the alternative syntax.

This is kind of in the same category as digraphs and trigraphs: strange stuff that arguably should never have been added to the language. The rationale for it all boils down to various locale-specific keyboards. I suppose it is possible that you'll see iso646.h, digraphs or trigraphs actually used in specific countries.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.