Boolean in C
-
I find it much easier to understand
if something is false
when I seeif (something == false)
than when I seeif (!something)
. Especially in longer expressions it is very easy to miss a single character like!
and read the code wrong.are you guys aware, that
not
is a valid keyword in c++ ? -
are you guys aware, that
not
is a valid keyword in c++ ?@J-Hilk
Yup. And it's devil's-spawn! ;-) [Same forand
&or
. If I wanted to program in Python or Pascal I would have picked that.] I would never use that, as "nobody" (most people) else uses it or knows about it, so I would regard it as an anti-pattern! -
are you guys aware, that
not
is a valid keyword in c++ ?@J-Hilk said in Boolean in C:
are you guys aware, that
not
is a valid keyword in c++ ?Yes but not in all compilers :-( MSVC does not recognize it.
-
@J-Hilk said in Boolean in C:
are you guys aware, that
not
is a valid keyword in c++ ?Yes but not in all compilers :-( MSVC does not recognize it.
-
@sierdzio
Good, but are you sure? Since it is valid since C99, I would have thought that MSVC would accept those?@JonB said in Boolean in C:
@sierdzio
Good, but are you sure? Since it is valid since C99, I would have thought that MSVC would accept those?Last time I tried was last year. Clang, GCC all are 100% fine with it, MSVC was throwing errors.
I now see it's supposed to be defined in some
iso646.h
header, I never included it, perhaps that's the reason. -
@J-Hilk said in Boolean in C:
are you guys aware, that
not
is a valid keyword in c++ ?Yes but not in all compilers :-( MSVC does not recognize it.
@sierdzio said in Boolean in C:
Yes but not in all compilers :-( MSVC does not recognize it.
VS been nonconforming! 😱 Color me surprised 😉
-
@JonB said in Boolean in C:
@sierdzio
Good, but are you sure? Since it is valid since C99, I would have thought that MSVC would accept those?Last time I tried was last year. Clang, GCC all are 100% fine with it, MSVC was throwing errors.
I now see it's supposed to be defined in some
iso646.h
header, I never included it, perhaps that's the reason. -
@sierdzio
If one has to include a header file for them, makes me wonder if they are not "part of the language", just should be available if you include the header. Are they just#define
s in that file??@JonB said in Boolean in C:
@sierdzio
If one has to include a header file for them, makes me wonder if they are not "part of the language", just should be available if you include the header. Are they just#define
s in that file??yup :D
#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 ^=
They are not actual C++ language reserved keywords.
-
@JonB said in Boolean in C:
@sierdzio
If one has to include a header file for them, makes me wonder if they are not "part of the language", just should be available if you include the header. Are they just#define
s in that file??yup :D
#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 ^=
They are not actual C++ language reserved keywords.
@sierdzio
Hmmmm.... So doesgcc
have these in some header file, or does their C++ actually have them as reserved? It does have aniso646.h
file, with the#define
s, yet you said they worked for you ingcc
without you explicitly including that? Does it include it automatically or from something else? -
@sierdzio
Hmmmm.... So doesgcc
have these in some header file, or does their C++ actually have them as reserved? It does have aniso646.h
file, with the#define
s, yet you said they worked for you ingcc
without you explicitly including that? Does it include it automatically or from something else?@JonB said in Boolean in C:
worked for you in gcc without you explicitly including that? Does it include it automatically or from something else
This header was originally in the C standard library as <iso646.h>. Compatibility header, in C defines alternative operator representations which are keywords in C++. This means that in a conforming implementation, including this header has no effect.
gcc has mostly a conforming implementation, at least in this regard
-
@JonB said in Boolean in C:
worked for you in gcc without you explicitly including that? Does it include it automatically or from something else
This header was originally in the C standard library as <iso646.h>. Compatibility header, in C defines alternative operator representations which are keywords in C++. This means that in a conforming implementation, including this header has no effect.
gcc has mostly a conforming implementation, at least in this regard
@J-Hilk said in Boolean in C:
This header was originally in the C standard library as <iso646.h>.
So what file is this in, which you say is included automatically?
-
@J-Hilk said in Boolean in C:
This header was originally in the C standard library as <iso646.h>.
So what file is this in, which you say is included automatically?
@JonB said in Boolean in C:
which you say is included automatically?
My understanding is that it is NOT included automatically in conforming C++ implementations because those understand these words as keywords and don't need this header file (which is only there for compatibility reasons).
-
@J-Hilk said in Boolean in C:
This header was originally in the C standard library as <iso646.h>.
So what file is this in, which you say is included automatically?
@JonB I'm talking about the iso646.h @sierdzio mentioned
https://en.cppreference.com/w/cpp/header/ciso646
Probably the reason why MSVC doesn't have those as keywords but requires this header is, IIRC, that it doesn't have/use a dedicated c compiler for c headers and it would break legacy stuff if those were used as keywords
-
@JonB said in Boolean in C:
which you say is included automatically?
My understanding is that it is NOT included automatically in conforming C++ implementations because those understand these words as keywords and don't need this header file (which is only there for compatibility reasons).
@jsulm
Mine too. But I quote from @sierdzio above:Last time I tried was last year. Clang, GCC all are 100% fine with it, MSVC was throwing errors.
I now see it's supposed to be defined in some iso646.h header, I never included it, perhaps that's the reason.
My question is (should be) aimed at him: he says it worked automatically in GCC/Clang (but not MSVC) with no
#include
from him, that's what I'm trying to understand. -
I know Boolean is someone's name.
But it kind of look like a diet fad to scare people skinny: boo-lean. -
@fcarney You mean Anne Boleyn, one of the wifes of king Henry VI which was executed. She was mother of Elisabeth I :-)
@jsulm said in Boolean in C:
@fcarney You mean Anne Boleyn, one of the wifes of king Henry VI which was executed. She was mother of Elisabeth I :-)
Ha! I'm not sure what a Boleyn variable would be. Dangerous in some manner.
Presumably @fcarney is referring to George Boole.
-
are you guys aware, that
not
is a valid keyword in c++ ?@J-Hilk said in Boolean in C:
are you guys aware, that not is a valid keyword in c++ ?
Heretic!
and the discussion is about C. ;^PBut to the point about superfluous comparisons: I guess is comes down to whether you understand the grammar. If you understand that all comparison operations evaluate to a boolean value (zero, or not zero) then it should become evident that explicit comparisons of booleans to a constant is redundant.
-
@jsulm said in Boolean in C:
@fcarney You mean Anne Boleyn, one of the wifes of king Henry VI which was executed. She was mother of Elisabeth I :-)
Ha! I'm not sure what a Boleyn variable would be. Dangerous in some manner.
Presumably @fcarney is referring to George Boole.
@jeremy_k said in Boolean in C:
Ha! I'm not sure what a Boleyn variable would be. Dangerous in some manner.
I guess technically I AM, being a decendent of Mary Boleyn...as for being dangerous... :^D
-
@jeremy_k said in Boolean in C:
Ha! I'm not sure what a Boleyn variable would be. Dangerous in some manner.
I guess technically I AM, being a decendent of Mary Boleyn...as for being dangerous... :^D
@Kent-Dorfman said in Boolean in C:
I guess technically I AM, being a decendent of Mary Boleyn
Are you also claiming to be a descendant of Henry VIII? :)