3 = 'c'` valid in C and C++?
This question already has an answer here:
All variable names must begin with a letter of the alphabet or an underscore. So yes, it is valid, except if you place it on file scope. (Be careful with double underscore though, it is reserved for the compiler internal use)
Yet, I wouldn't recommend having variables with names like that, since it may be confusing for the reader.
From the C++ 2003 standard:
17.4.3.1.2 Global names [lib.global.names]
Certain sets of names and function signatures are always reserved to the implementation:
165) Such names are also reserved in namespace ::std (17.4.3.1).
It's valid in any scope other than global scope1.
C++17 - n4659 / [lex.name]
In addition, some identifiers are reserved for use by C++ implementations and shall not be used otherwise; no diagnostic is required.
The standard library actually has an example of it in namespace scope, inherited from boost
: The placeholders for std::bind
.
And C has similar phrasing:
C11 - n1570 / 7.1.3 Reserved identifiers
Each header declares or defines all identifiers listed in its associated subclause, and optionally declares or defines identifiers listed in its associated future library directions subclause and identifiers which are always reserved either for any use or for use as file scope identifiers.
Though the choice of scopes is more limited.
1 - Not a normative term, just a bastardization of the terms used by the two standards.
链接地址: http://www.djcxy.com/p/40318.html上一篇: C ++:标识符规则不起作用
下一篇: 3 ='c'在C和C ++中有效吗?