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:36

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.

查看更多
Root(大扎)
3楼-- · 2019-01-21 16:40

keyword, - a word with special meaning in a particular context. It's semantic definition.

reserved word is a word that cannot be used as an identifier - such as, variable, and function name. It's syntactic definition.

E.g.In Java, all keywords are reserved words. Probably not the reverse. goto is reserved word but not used and has no function.

In older languages like FORTRAN there were keywords but no reserved words.

However, keyword and reserved word are used interchangeably.

查看更多
女痞
4楼-- · 2019-01-21 16: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.

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-01-21 16:50

Just to show that the distinction is very meaningful:

Not in all languages are all keywords reserved words. In Fortran it is possible to do this:

if if then then else else

In this case, the keywords are not reserved, but depending on context can be interpreted by the compiler as variables.

查看更多
登录 后发表回答