What is the difference between “keyword” and “rese

2019-01-21 15:52发布

What's the difference between a keyword and a reserved word?

For example, in the proposal for concepts in C++ one can read the following statement:

This proposal introduces five new keywords: concept, concept map, where, axiom, and late check. All of these keywords will also be reserved words.

10条回答
家丑人穷心不美
2楼-- · 2019-01-21 16:29
  • Keyword: It has some meaning and we can use in program.
  • Reserved word: We can't use in program. They may be used in future. Example: goto
查看更多
劫难
3楼-- · 2019-01-21 16:30

A good example of this distinction is "goto" in Java. It's not a language keyword (i.e. it's not valid Java), but it is a reserved word.

It seems that the java designers are telling us "We're not going to use 'goto', and neither are you".

查看更多
看我几分像从前
4楼-- · 2019-01-21 16:30

Wiki says this "A keyword is a word that is special only in certain contexts but a reserved word is a special word that cannot be used as a user-defined name."

http://en.wikipedia.org/wiki/Reserved_word#Reserved_word_vs._keyword

查看更多
兄弟一词,经得起流年.
5楼-- · 2019-01-21 16:31

Keywords have a special meaning in a language, and are part of the syntax.

Reserved words are words that cannot be used as identifiers (variables, functions, etc.), because they are reserved by the language.

In practice most keywords are reserved words and vice versa. But because they're two different things it may happen that a keyword is not a reserved word (e.g. a keyword only has meaning in a special context, and can therefore be used as an identifier), or a reserved word is not a keyword (e.g. because it is reserved for future use).

Update: Some examples as given by others that illustrate the distinction:

  • In Java, goto is a reserved word but not a keyword (as a consequence, you cannot use it at all)
  • Fortran has no reserved words, all keywords (if, then, etc.) can be used as identifiers
查看更多
【Aperson】
6楼-- · 2019-01-21 16:31

Reserved words and keywords are mostly the same and they have pre-defined meanings in GW-BASIC...these have pre-defined uses and cannot be used or re-defined for any other purpose in Basic. Keywords cannot be used as a variable name. Some of the keywords of Basic are...IF, THEN, WHILE etc..

查看更多
在下西门庆
7楼-- · 2019-01-21 16:34

I guess keyword is a word used as "keyword" (like if, for, switch, etc...) while a reserved word is something you cannot use as variable name because it might become a keyword in a future version of the language.

查看更多
登录 后发表回答