C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Reserved identifiers

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Yevgen Muntyan
Guest





PostPosted: Sun Oct 17, 2004 1:35 am    Post subject: Reserved identifiers Reply with quote



Hello all,

I found a web page ([url]http://oakroadsystems.com/tech/cppredef.htm)[/url], which
says:

--------------------------------------------------------------------
...never make up any identifier that starts with an underscore.

(Strictly speaking, a leading underscore followed by a digit or
lower-case letter is legal in your own namespaces (but never in the
global namespace or ::std): 17.4.3.1.2/1 [lib.global.names]. However,
articles in the comp.std.c++ newsgroup have warned that some compilers
do improperly use such identifiers for their own purposes, so my advice
is to steer clear. A trailing single underscore should be fine.)
--------------------------------------------------------------------

This web page is two years old, so I have two questions:

Are there some plans to change this, namely can I be sure (at least for
now) that identifiers like _blah may be used "in my own namespaces"?

What about class members? May member of class in global namespace have
name starting with underscore?

(Sorry, I don't have a copy of C++ standard)

Thank you,
Yevgen

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Mon Oct 18, 2004 6:25 pm    Post subject: Re: Reserved identifiers Reply with quote



Yevgen Muntyan <muntyan.removethis (AT) tamu (DOT) edu> wrote


Quote:
I found a web page ([url]http://oakroadsystems.com/tech/cppredef.htm)[/url], which
says:

--------------------------------------------------------------------
...never make up any identifier that starts with an underscore.

(Strictly speaking, a leading underscore followed by a digit or
lower-case letter is legal in your own namespaces (but never in the
global namespace or ::std): 17.4.3.1.2/1 [lib.global.names]. However,
articles in the comp.std.c++ newsgroup have warned that some compilers
do improperly use such identifiers for their own purposes, so my advice
is to steer clear. A trailing single underscore should be fine.)
--------------------------------------------------------------------

This web page is two years old, so I have two questions:

Are there some plans to change this, namely can I be sure (at least for
now) that identifiers like _blah may be used "in my own namespaces"?

Plans by whom? The standard has always said you could; before the C++
standard, the C standard (1989) said you could. The last time I checked
(about a year ago), there were still occasional violations in some
system headers. If the implementations haven't gotten it cleaned up in
15 years, I rather doubt that they will get it cleaned up in the future.

(To be fair, the violations were all in conditionally compiled parts of
the headers. If you gave all of the options necessary for 100% ISO
C/C++ compatibility, there would be no problem. But also no threads, no
sockets, no synchronized IO...)

Quote:
What about class members? May member of class in global namespace have
name starting with underscore?

According to the standard, yes. In practice, it's better to avoid it.

--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ben Hutchings
Guest





PostPosted: Mon Oct 18, 2004 7:05 pm    Post subject: Re: Reserved identifiers Reply with quote



Yevgen Muntyan wrote:
Quote:
Hello all,

I found a web page ([url]http://oakroadsystems.com/tech/cppredef.htm)[/url], which
says:

--------------------------------------------------------------------
...never make up any identifier that starts with an underscore.

(Strictly speaking, a leading underscore followed by a digit or
lower-case letter is legal in your own namespaces (but never in the
global namespace or ::std): 17.4.3.1.2/1 [lib.global.names]. However,
articles in the comp.std.c++ newsgroup have warned that some compilers
do improperly use such identifiers for their own purposes, so my advice
is to steer clear. A trailing single underscore should be fine.)
--------------------------------------------------------------------

This web page is two years old, so I have two questions:

Are there some plans to change this, namely can I be sure (at least for
now) that identifiers like _blah may be used "in my own namespaces"?

The standard already says they may, so what should be changed? Are
you asking whether the implementations that don't conform in this
respect have been fixed?

Quote:
What about class members? May member of class in global namespace have
name starting with underscore?
snip


Yes, they may, but again it's probably inadvisable. Names beginning
with underscores might well be used for macros, meaning that they
will prevent the use of those names in any namespace.

--
Ben Hutchings
When in doubt, use brute force. - Ken Thompson

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ron Natalie
Guest





PostPosted: Mon Oct 18, 2004 7:13 pm    Post subject: Re: Reserved identifiers Reply with quote

Yevgen Muntyan wrote:

Quote:
Are there some plans to change this, namely can I be sure (at least for
now) that identifiers like _blah may be used "in my own namespaces"?

The rule is strictly:

1. Two consecutive underscores (anywhere in the identifier) are reserved everywhere.
2. A leading underscore followed by a capital letter is reserved everywhere.
3. Leading underscores followed by other characters are reserved in the global
namespace and ::std.

You can hence use _foo (underscore followed by lower case)
as an identifier in your own namespace. You can't use underscore followed
by an underscore or uppercase letters.

Quote:

What about class members? May member of class in global namespace have
name starting with underscore?

A class member (regardless of where the class is defined) is in the namespace
of the class itself. Hence, you can use _ followed by a lowercase letter as
a member name no matter where the class is defined.

Quote:

(Sorry, I don't have a copy of C++ standard)

Invest in one.


This isn't likely to change. The reasons aren't stated in the standard, but
even with namespaces, there is need for these reservations.

First, double underscore is used a lot as C++ is retrofitted into C sytle linkers
that need some extra "decoration." __ is frequently used to set off the decoration
from the name.

Second, the _UPPER are used to deal with the preproessor and preprocesor interference
with the impementation. For example, if you look at some of the standard headers
you'll find that the definitions use internal variables of the form _UPPER because
they know that conforming programs won't do something like #define those to something
that could mess up the implementation.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.