Reserved Identifiers (just making sure)

naptime via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 12 08:20:10 PST 2016


Hello,


I already know the answer to my question, but I would like 
someone to reassure me that I'm not mistaken before I rename 
literally hundreds of identifiers in my code (and refactor at 
least two large templates).

TL;DR:  Am I understanding correctly that "_Foo" is NOT reserved 
as an identifier in the sense that "__foo" IS reserved, since 
they both are reserved in C?


I have been using D for about two years.  Before that, I wrote 
everything in strict ANSI C.  In C, not only are identifies 
beginning with two underscores reserved (e.g. __foo), but 
identifiers beginning with a single underscore followed by a 
capital letter are also reserved (e.g. _Foo)†.  I would like to 
verify that this is not the case in D.  To be absolutely clear, I 
already know that such identifiers compile; I want to know if 
they are reserved for future use by the D language.


The following quote is from:
https://dlang.org/spec/lex.html#Identifier

Quote:
"Identifiers start with a letter, _, or universal alpha, and are 
followed by any number of letters, _, digits, or universal 
alphas. Universal alphas are as defined in ISO/IEC 9899:1999(E) 
Appendix D. (This is the C99 Standard.) Identifiers can be 
arbitrarily long, and are case sensitive. Identifiers starting 
with __ (two underscores) are reserved."


The above quote makes it perfectly clear that identifiers 
beginning with an underscore followed by an uppercase letter are 
not reserved, but I could not find an example of such in 
object.d, DRuntime, nor in Phobos2 source (my usual method of 
verification).  Could someone who knows for sure please verify 
that "_Foo" is not reserved in D?


Thank you for your patience, and in advance for any assistance!


†(, as well as some other obscure restrictions e.g. all-uppercase 
identifiers beginning with 'E' are reserved in C.)


More information about the Digitalmars-d-learn mailing list