Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Reserved word
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Specification== The list of reserved words and keywords in a language are defined when a language is developed, and both form part of a language's [[formal specification]]. Generally one wishes to minimize the number of reserved words, to avoid restricting valid identifier names. Further, introducing new reserved words breaks existing programs that use that word (it is not backwards compatible), so this is avoided. To prevent this and provide [[forward compatibility]], sometimes words are reserved without having a current use (a reserved word that is not a keyword), as this allows the word to be used in future without breaking existing programs. Alternatively, new language features can be implemented as predefineds, which can be overridden, thus not breaking existing programs. Reasons for flexibility include allowing compiler vendors to extend the specification by including non-standard features, different standard dialects of language to extend it, or future versions of the language to include additional features. For example, a procedural language may anticipate adding [[Object-oriented programming|object-oriented]] capabilities in a future version or some dialect, at which point one might add keywords like <code>class</code> or <code>object</code>. To accommodate this possibility, the current specification may make these reserved words, even if they are not currently used. A notable example is in [[Java (programming language)|Java]], where <code>const</code> and <code>goto</code> are reserved words — they have no meaning in Java but they also cannot be used as identifiers. By reserving the terms, they can be implemented in future versions of Java, if desired, without breaking older Java source code. For example, there was a proposal in 1999 to add C++-like <code>const</code> to the language, which was possible using the <code>const</code> word, since it was reserved but currently unused; however, this proposal was rejected – notably because even though adding the feature would not break any existing programs, using it in the standard library (notably in collections) ''would'' break compatibility.<ref>{{cite web|url=http://bugs.java.com/view_bug.do?bug_id=4211070 |title=Bug ID: JDK-4211070 Java should support const parameters (like C++) for code {{sic|maint|ainence|nolink=y}} |publisher=Bugs.sun.com |access-date=2014-11-04}}<!-- was previously at: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4211070 2013-08-18 --></ref> [[JavaScript]] also contains a number of reserved words without special functionality; the exact list varies by version and mode.<ref>{{Cite web|url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar|title=Lexical grammar - JavaScript | MDN|website=developer.mozilla.org|date=8 November 2023 }}</ref> Languages differ significantly in how frequently they introduce new reserved words or keywords and how they name them, with some languages being very conservative and introducing new keywords rarely or never, to avoid breaking existing programs, while other languages introduce new keywords more freely, requiring existing programs to change existing identifiers that conflict. A case study is given by new keywords in [[C11 (C standard revision)|C11]] compared with [[C++11]], both from 2011 – recall that in C and C++, identifiers that begin with an underscore followed by an uppercase letter are reserved:<ref>C99 specification, 7.1.3 Reserved identifiers: "All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use."</ref> {{quote|The C committee prefers not to create new keywords in the user name space, as it is generally expected that each revision of C will avoid breaking older C programs. By comparison, the C++ committee (WG21) prefers to make new keywords as normal‐looking as the old keywords. For example, C++11 defines a new <code>thread_local</code> keyword to designate static storage local to one thread. C11 defines the new keyword as <code>_Thread_local.</code> In the new C11 header <threads.h>, there is a macro definition to provide the normal‐looking name:<ref>[http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3631.pdf C11:The New C Standard], Thomas Plum, "A Note on Keywords"</ref> :<code>#define thread_local _Thread_local</code> }} That is, C11 introduced the keyword <code>_Thread_local</code> within an existing set of reserved words (those with a certain prefix), and then used a separate facility (macro processing) to allow its use as if it were a new keyword without any prefixing, while C++11 introduce the keyword <code>thread_local</code> despite this not being an existing reserved word, breaking any programs that used this, but without requiring macro processing.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)