Logical OR operator

Started by
19 comments, last by Boooke 12 years, 1 month ago
Hey again. I understand then. I really liked the idea of the toupper (and similar) function. I have used similar in before, but not in C++. It has quite some uses. Could help eliminate lines of code.


Things are similar with the bit-wise OR. Because of
'y' in ASCII / UTF-8 is 79[sub]hex[/sub]
'Y' in ASCII / UTF-8 is 59[sub]hex[/sub]
the difference is just 20[sub]hex[/sub], what is typical for all latin letters. Hence
( ch | 0x20 ) == 'y'
can be used to check for both 'y' and 'Y'. However, also here the parentheses are required, or else the == would be evaluated before the |.


I haven't worked with the bit-wise operators before, so I wouldn't know why it would work, and how it compares, though.
Advertisement


( ch | 0x20 ) == 'y'
can be used to check for both 'y' and 'Y'. However, also here the parentheses are required, or else the == would be evaluated before the |.
[/quote]
This is "for beginners". And even if it were not - if I saw code like that, I wouldn't have a clue what it was trying to do at first glance.
@Edited: I got wrong.
(( I am learning English. ))
That does not work. It is interpreted as the expression 'y' or ('Y' == ch), which is always true.
[s]Additionally, "or" is not a keyword in C++, so you'd get a compiler error anyway if you tried [font=courier new,courier,monospace]('y' or 'Y' == ch)[/font].[/s]

[edit]

Ignore this. I'd delete it but then SiCrane's post wouldn't make sense. Learn something new every day.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

Additionally, "or" is not a keyword in C++, so you'd get a compiler error anyway if you tried [font=courier new,courier,monospace]('y' or 'Y' == ch)[/font].

or is an alternate token for || and has been since before the first standard. (See Section 2.5 ISO/IEC 14882:1998)

[quote name='Cornstalks' timestamp='1329929945' post='4915555']
Additionally, "or" is not a keyword in C++, so you'd get a compiler error anyway if you tried [font=courier new,courier,monospace]('y' or 'Y' == ch)[/font].

or is an alternate token for || and has been since before the first standard. (See Section 2.5 ISO/IEC 14882:1998)
[/quote]
I, good sir, am a moron. Thanks for the correction. I get so used to using the symbols that I forget that keywords like and, or, xor, etc. even exist.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

[quote name='Cornstalks' timestamp='1329929945' post='4915555']
Additionally, "or" is not a keyword in C++, so you'd get a compiler error anyway if you tried [font=courier new,courier,monospace]('y' or 'Y' == ch)[/font].

or is an alternate token for || and has been since before the first standard. (See Section 2.5 ISO/IEC 14882:1998)
[/quote]


... learned something new.


Oddly enough, I don't think I have ever encountered it in use.
It's only really used by people who's keyboards don't have a convenient key for |. So like code written by Danish people ten or more years ago.

It's only really used by people who's keyboards don't have a convenient key for |. So like code written by Danish people ten or more years ago.

So that's why Bjarne Stroustrup included them...
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

This topic is closed to new replies.

Advertisement