What is the difference between “keyword” and “reserved word”?

前端 未结 10 2434
再見小時候
再見小時候 2020-12-13 05:54

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

相关标签:
10条回答
  • 2020-12-13 06:33

    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

    0 讨论(0)
  • 2020-12-13 06:38

    Really it will depend a lot on context. For example, the ISO C++ Standard says that things like "if", "while", "int" etc. are keywords, and doesn't actually use the term reserved word, except once, in a footnote, where something else was probably meant :-)

    The standard doe specify reserved names - for example, all names that begin with an underscore and an uppercase letter are reserved names.

    0 讨论(0)
  • 2020-12-13 06:44

    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".

    0 讨论(0)
  • 2020-12-13 06:47

    Keywords : Keywords has some special functionalities to the compiler. So the keywords can not be used as identifiers in coding. Reserved words: Reserve words are the words which are reserved for future use. In java, const and goto are the reserved words which are not being used currently and may be brought back to java in the future. If we check here Java Language Keywords (https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html) , It says that java (latest I guess) has 50 keywords including goto and const. So goto and const are the keywords which are reserved.

    0 讨论(0)
提交回复
热议问题