0

I think there are reserved keywords in C++ , why they are called 'reserve keywords ' and categorized as different?

4
  • 1
    Since we're on the topic of how things are named, I assume you meant reserved keywords? Commented Nov 14, 2010 at 9:12
  • 2
    This comment is reserved. We were planning on putting it to use but the committee couldn't agree on an acceptable wording so we're putting that off until the next standard. Commented Nov 14, 2010 at 9:14
  • 1
    I'm going to edit your question into being proper English. :-) And yes, keywords exist in almost all computer languages. Perhaps the only exception to that rule are languages derived from lisp and Forth. Commented Nov 14, 2010 at 9:23
  • 2
    possible duplicate of What's the difference between "keyword" and "reserved word"? Commented Nov 14, 2010 at 9:40

4 Answers 4

5

Words used by the language (if, for, while, struct, etc.) are sometimes called reserved words or keywords. I suspect that many people also call them reserved keywords.

However, there are also words that the Committee may want to use in the future but that aren't currently used. I would consider these reserved keywords. In Java goto is a reserved word that isn't currently used (although I believe the idea is that it won't ever be used). This kind of reserved keyword isn't allowed as a variable name, function name, class, struct or enum name, etc. But without any use in the language today, it wouldn't really be allowed in valid C++ at all.

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

Comments

2

Reserved words or keywords are predefined words with special meanings in that language:
http://en.wikipedia.org/wiki/Reserved_word
http://en.wikipedia.org/wiki/Keyword_(computer_programming)

Comments

1

Keywords are names like "if" or "while" used in the syntax of the language. If they are reserved, they can't be used as identifiers. If they aren't reserved (contextual keywords) they can be used as identifiers, they are used as keywords only in specific contexts (where identifiers can't appear, or if they can, there is some rule which gives priority to the identifier or to the keyword function). C++0X will probably have contextual keywords. A language famous for its (ab)use contextual keywords was PL/I in which you could write something like:

IF IF THEN THEN = ELSE; ELSE ELSE = THEN; 

(Obviously, the sane approach is to consider even the contextual keywords reserved; the utility is contextual keywords is helping migration).

Comments

1

And let's end with a C++ reserved keyword story: When I just began learning C++ I had the worst teacher.

One of his assignments was to write a "phone book". The design we were given was pretty simple,

you have a phone book class which stores an array of classes called: friend. Back in the days I studied C++ we didn't had internet.

So half of us had a compilation problem and the other half didn't. Our teacher just shrugged and said "No problem, half of you failed". It took us time to realize that the half that had the compilation problem were the half that the friend word was colored different in the IDE, the same color that the struct \ enum \ class keywords were colored. The other half called their class Friend (capital F).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.