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 

Underline importance of forbidden names

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





PostPosted: Thu Mar 17, 2005 2:22 am    Post subject: Underline importance of forbidden names Reply with quote



Hi All,

Could someone please double check, if I remember right, or did I miss
something about reserved names?

The following names are reserved for the implementation:

- any name containing two consecutive underscores

- any global namespace level name, starting with an underscore (does this
forbid such names in unnamed namespaces as well?)

- any name starting with an underscore followed by an uppercase letter

- any namespace level name starting with the letters str followed by a
lowercase letter

Did I miss anything? Is anything I wrote wrong?

It is probably worth to mention the "MACRO NAMESPACE" also in this list
(although only convention)?

--
Attila aka WW



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





PostPosted: Thu Mar 17, 2005 12:39 pm    Post subject: Re: Underline importance of forbidden names Reply with quote



On Wednesday 16 March 2005 09:22 pm, Attila Feher wrote:

Quote:
The following names are reserved for the implementation:
.....
- any namespace level name starting with the letters str followed by a
lowercase letter

My understanding is that these are names are reserved only if <cstdlib>
is included. (Of course, one never knows whether <cstdlib> is included
if you have included at least one standard header.)

Reserved identifiers from the C90 standard are (section 7.13):

<cerrno>: macros that begin with E<digit> or E<uppercase>.
<cctype>: Functions that start with is<lower> or to<lower>.
<clocale>: Macros that start with LC_<upper>
<cmath>: all the math functions with a suffix of "f" or "l"
<csignal>: Macros that start with SIG<upper> or SIG_<upper>
<cstdlib>: Functions that start with str<lower>
<cstring>: Functions that start with str<lower>, mem<lower>, or
wcs<lower>.
--
Ray Lischner, author of C++ in a Nutshell
http://www.tempest-sw.com/cpp

[ 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: Thu Mar 17, 2005 9:52 pm    Post subject: Re: Underline importance of forbidden names Reply with quote



Attila Feher wrote:

Quote:
Could someone please double check, if I remember right, or did
I miss something about reserved names?

The following names are reserved for the implementation:

- any name containing two consecutive underscores

- any global namespace level name, starting with an underscore (does
this
forbid such names in unnamed namespaces as well?)

No. A name in an unnamed namespace is not in global namespace.

Quote:
- any name starting with an underscore followed by an uppercase
letter


Quote:
- any namespace level name starting with the letters str
followed by a lowercase letter

Did I miss anything? Is anything I wrote wrong?

It is probably worth to mention the "MACRO NAMESPACE" also in
this list (although only convention)?

I think that your last point is wrong, at least in C++. In C,
there is a section concerning future library directions, which
reserves a lot of names for future library extensions:

-- all names beginning with is or to, followed by a lower case
letter, if you include <ctype.h> or <wctype.h>;

-- all names beginning with E followed by a digit or an upper
case letter, if you include <errno.h>;

-- all names beginning with PRI or SCN followed by a lower case
letter or an X, if you include <inttypes.h>;

-- all names beginning with LC_ followed by an upper case
letter if you include <locale.h>;

-- all names beginning with SIG or SIG_ followed by an upper
case letter, if you include <signal.h>;

-- all names beginning with int or uint and ending with _t, and
names beginning with INT or UINT and ending with _MAX, _MIN
or _C, if you include <stdint.h>;

-- all names beginning with str followed by a lower case
letter, if you include <stdlib.h> or <string.h>;

-- all names beginning with mem followed by a lower case
letter, if you include <string.h>; and

-- all names beginning with wcs and a lower class letter, if
you include <string.h> or <wchar.h>.

Plus, of course, anything formally defined in the header.

That's a lot, but note that the restrictions are only if you
include the specified header.

The case of C++ is significantly different. To begin with,
unlike C, in C++, one standard header can include any of the
others. So the restriction "only if you include the given
standard header" cannot apply. On the other hand, except for
the <xxx.h> compatibility headers, the C++ standard puts almost
everything in std:: (and allows almost no macros). The result
is that for the most part, you don't have to worry about any of
the above -- the next version of the standard can add pretty
much anything it wants to std:: without risk of breaking your
code.

There are a few issues that the standard doesn't seem to
mention. Presumably, for example, the C++ standard will extend
the <c...> headers to track fairly closely what the C standard
does. This means that in the cases above where the name is
required to be a macro, if you include the corresponding <c...>
header, you have to avoid the names as well. (Roughly speaking,
and without verifying, this would be the names using upper case
letters.)

Other than this, you have also forgotten all of the keywords and
alternate tokens.

And of course, that is for the standard. In practice, no
compiler I know implements the <c...> includes correctly, so you
risk problems if you define anything in the global namespace
whose name is the same as that of a standard C function, even if
you include the <c...> form of the header; for that matter,
there is a decided risk that the implementation of the library
uses some of the C functions in global namespace, so if you
define a function `extern "C" memcpy', for example, you're
looking for trouble (but there is no exhaustive list that I know
of, and technically, the standard says you have the right, as
long as you don't include <string.h>).

Finally, of course, you're probably not using C++ in a vacuum.
I know that I almost never write an application of any size
which doesn't use some Posix functionality; the situation is
doubtlessly the same for people working on Windows platforms.
And Posix introduces a lot more reserved symbols, etc. (On my
platform, Solaris, there are even a few macros with names
beginning with a _, followed by a lower case letter. Which
means that using such symbols is bad even in private scopes.)

In the end, the rules are 1) complicated, 2) not very clear, and
3) they vary from one platform to the next. Pragmatically, I
avoid all symbols beginning with a _ or containing two
successive __, avoid all standard and system standard function
names that I know, at least at global scope, and hope that the
compiler will complain, or at least that the code will core dump
immediately, if I accidentally get a collision. Not really a
very satisfactory solution, but I don't have anything better.

--
James Kanze GABI Software
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
White Wolf
Guest





PostPosted: Thu Mar 17, 2005 9:56 pm    Post subject: Re: Underline importance of forbidden names Reply with quote

Ray Lischner wrote:
Quote:
On Wednesday 16 March 2005 09:22 pm, Attila Feher wrote:

The following names are reserved for the implementation:
....
- any namespace level name starting with the letters str followed by a
lowercase letter

My understanding is that these are names are reserved only if <cstdlib
is included. (Of course, one never knows whether if you have included at least one standard header.)

Well, my point is that I would like to keep it simple; and since the people
I will talk to (well, mail to but that is irrelevant) will never write
production code without using 3rd party libraries, for them these names are
simply not allowed. Since any 3rd party library (linked into the
application) might have used any of those headers. In which case the
problems will come during linking - which happens at startup, in the worst
case.

Quote:
Reserved identifiers from the C90 standard are (section 7.13):

cerrno>: macros that begin with E<digit> or E<uppercase>.
cctype>: Functions that start with is<lower> or to<lower>.
clocale>: Macros that start with LC_<upper
cmath>: all the math functions with a suffix of "f" or "l"
csignal>: Macros that start with SIG<upper> or SIG_<upper
cstdlib>: Functions that start with str<lower
cstring>: Functions that start with str<lower>, mem<lower>, or
wcs<lower>.

Thank you Ray, this is just excellent! I did not know most of the above.
Shame on me, but I am clever enough to ask. :-)

I guess the list above says, that those are in the std/global namespace. I
can have my strcpy in the buffer_overflow namespace, and still be compliant
right? I - of course - meant the function name issues, not the MACROs. :-)

IIRC C++ does not allow functions to be macros, so they cannot "invade" a
namespace or (class) scope right?

--
WW aka Attila
:::
If you always do what you've always done, you'll always get what you've
always gotten.



[ 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: Sat Mar 19, 2005 12:14 am    Post subject: Re: Underline importance of forbidden names Reply with quote

Ray Lischner wrote:
Quote:
On Wednesday 16 March 2005 09:22 pm, Attila Feher wrote:

The following names are reserved for the implementation:
....
- any namespace level name starting with the letters str followed
by a
lowercase letter

My understanding is that these are names are reserved only if
cstdlib> is included.

<cstdlib>, <stdlib.h>, <string> or <string.h>.

Quote:
(Of course, one never knows whether <cstdlib> is included if
you have included at least one standard header.)

No. Or at least I don't think so. As I understand it, the C
rules rule for the C header files, including the <cxxx>
variants.

Of course, in practice, you don't include just standard headers,
and you can't generally be too sure about what the other headers
you include might include.

--
James Kanze GABI Software
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: Tue Mar 22, 2005 9:06 am    Post subject: Re: Underline importance of forbidden names Reply with quote

White Wolf wrote:
Quote:
Ray Lischner wrote:
snip
Reserved identifiers from the C90 standard are (section 7.13):

cerrno>: macros that begin with E<digit> or E<uppercase>.
cctype>: Functions that start with is<lower> or to<lower>.
clocale>: Macros that start with LC_<upper
cmath>: all the math functions with a suffix of "f" or "l"
csignal>: Macros that start with SIG<upper> or SIG_<upper
cstdlib>: Functions that start with str<lower
cstring>: Functions that start with str<lower>, mem<lower>, or
wcs<lower>.

Thank you Ray, this is just excellent! I did not know most of the above.
Shame on me, but I am clever enough to ask. :-)

I guess the list above says, that those are in the std/global namespace. I
can have my strcpy in the buffer_overflow namespace, and still be compliant
right? I - of course - meant the function name issues, not the MACROs. :-)

IIRC C++ does not allow functions to be macros, so they cannot "invade" a
namespace or (class) scope right?

Correct. The functions from the C library that the C standard allows
to be macros as well are supposed to be defined only as functions in
the C++ library. I don't know whether there are any current
implementations that violate this; I don't remember running into
myself. Of course there are a few names that are defined as macros in
both versions of the library, notably "assert".

--
Ben Hutchings
Having problems with C++ templates? Your questions may be answered by
<http://womble.decadentplace.org.uk/c++/template-faq.html>.

[ 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.