Skip to main content
gamedev.net
🔒 Locked

C++ Keyword?

Started by KodeNerd Jul 20, 2008 at 6:07 PM 12 replies 1.8k views
Original Post
KodeNerd
KodeNerd
Did the words "and" and "or" become C++ keywords, or is it just Code::Blocks that is saying that they are?
------------George Gough
Ezbez
Ezbez
IIRC, they are optional keywords that quite a few compilers support. They are in the standard, but aren't required to be supported.
Sneftel
Sneftel
All compilers are required to support them. It's the same in C, but you must include iso646.h to get them.
dmatter
dmatter
VC++2008 doesn't seem to support them without #include . In C++ I think they're meant to 'just work' without any headers, but whatever. [rolleyes]
KodeNerd
KodeNerd
Do they do the same thing as && and ||?
------------George Gough
fpsgamer
fpsgamer
Quote:
Original post by PKLoki
More to the point, if they work the same why not just use && and ||? Less typing!


Another mystery solved:

Quote:

[iso646.h] defines a number of macros which allow programmers to use C language bitwise and logical operators, which, without the header file, cannot be quickly or easily typed on some international and non-QWERTY keyboards.


It simply was not possible to type thoes symbols on some keyboards :)

Simiarly trigraphs were introduced to solve the same problem (albeit for different characters).

Quote:

The reason for their existence is that the basic character set of C (a subset of the ASCII character set) includes nine characters which lie outside the ISO 646 invariant character set. This can pose a problem for writing source code if the keyboard being used does not support any of these nine characters. The ANSI C committee invented trigraphs as a way of entering source code using keyboards that supported any version of the ISO 646 character set. Non-ASCII ISO 646 character sets are not much used today, but trigraphs remain in the C99 standard[


[Edited by - fpsgamer on July 20, 2008 8:29:42 PM]
Zahlman
Zahlman
Or you could use them to save the person reading the code the mental effort of translating the symbol into the English word. And seriously - that's a savings of one character for '&&' vs 'and', and zero for '||' vs 'or'. Big whoop.
Simian Man
Simian Man
Quote:
Original post by Zahlman
Or you could use them to save the person reading the code the mental effort of translating the symbol into the English word. And seriously - that's a savings of one character for '&&' vs 'and', and zero for '||' vs 'or'. Big whoop.


Actually if you count having to hit the shift key (on American keyboards at least), && is the same at three strokes and || is more typing than or.
dave
dave
All of the monkeys in the room are much more likely to type && than and.
fpsgamer
fpsgamer
Quote:
Original post by Dave
All of the monkeys in the room are much more likely to type && than and.


You'd think so, but I have examples from work that say otherwise [grin]
implicit
implicit
Great.. So now we have trigraphs, digraphs and these cute and/or things to deal with what ought to be a non-issue nowadays. Besides if you wanted to speed up typing then wouldn't begin/end macros for { and } have made a lot more sense? IIRC those took a three-key combo involving the numpad on my Amiga.

Here's the deal, if you're a C programmer then you can bloody well buy yourself an English keyboard or at least switch to a reasonable keyboard layout. That's what I do, and so does every other coder I know.
daviangel
daviangel
Quote:
Original post by dmatter
VC++2008 doesn't seem to support them without #include . In C++ I think they're meant to 'just work' without any headers, but whatever. [rolleyes]

Yeah , Microsoft's compiler is nonconforming in this area since you should be able to use them without needing to include the header:
These identifiers are keywords in the ISO C++ programming language and do not require the inclusion of a header file. For consistency, however, the C++98 standard provides the header .

I found this out a while back trying to compile a custom library that makes liberal use of the new keywords and couldn't get it to compile under MS VC++ and at the time the MSDN help system never mentioned iso646 was necessary and it took me a while to figure out I needed to include that header!
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.