Topic: underscores and their limited uses in C++ names
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1999/04/22 Raw View
In article <MPG.11854d4cb7f494729898be@news.mindspring.com>, Stan Brown
<brahms@mindspring.com> writes
>The section head "global names" is unfortunate, because it seems only the
>second clause is actually about global names. As I read the text of that
>section, you may *never* use leading underscore followed by a capital
>letter for your own purposes; it is *always* reserved to the
>implementation. Leading underscore followed by something else is, in
>theory, yours to use as long as you're not in the global namespace; but
>I'll bet there are common compilers that get that wrong.
Exactly how do you propose that a compiler gets it right? Must it know
if the author of code is an implementor? Do not expect compilers to
protect you from errors in this area.
Francis Glassborow Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: aGriffiths@ma.demon.co.uk (Alan Griffiths)
Date: 1999/04/22 Raw View
In article <AsnV3qAETfH3EwPp@robinton.demon.co.uk>
francisG@robinton.demon.co.uk "Francis Glassborow" writes:
> In article <MPG.11854d4cb7f494729898be@news.mindspring.com>, Stan Brown
> <brahms@mindspring.com> writes
> >The section head "global names" is unfortunate, because it seems only the
> >second clause is actually about global names. As I read the text of that
> >section, you may *never* use leading underscore followed by a capital
> >letter for your own purposes; it is *always* reserved to the
> >implementation. Leading underscore followed by something else is, in
> >theory, yours to use as long as you're not in the global namespace; but
> >I'll bet there are common compilers that get that wrong.
>
> Exactly how do you propose that a compiler gets it right? Must it know
> if the author of code is an implementor? Do not expect compilers to
> protect you from errors in this area.
An obvious mechanism is to disable the warning for text included via
"angle bracket" inclusion. (No real need to worry about compiling the
library itself - that isn't the case of concern.)
--
Alan Griffiths (alan.griffiths@experian.com, +44 115 934 4517)
Senior Systems Consultant, Experian
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1999/04/22 Raw View
Francis Glassborow wrote:
>
> In article <MPG.11854d4cb7f494729898be@news.mindspring.com>, Stan Brown
> <brahms@mindspring.com> writes
> >The section head "global names" is unfortunate, because it seems only the
> >second clause is actually about global names. As I read the text of that
> >section, you may *never* use leading underscore followed by a capital
> >letter for your own purposes; it is *always* reserved to the
> >implementation. Leading underscore followed by something else is, in
> >theory, yours to use as long as you're not in the global namespace; but
> >I'll bet there are common compilers that get that wrong.
>
> Exactly how do you propose that a compiler gets it right? Must it know
> if the author of code is an implementor? Do not expect compilers to
> protect you from errors in this area.
An easy solution would be a special pragma that tells the compiler
that the corresponding header or source file is part of the
implementation. Of course, you cannot prevent the user from using
it, too, but then his program is not conforming any more anyway. If
encountered in a header file, the pragma of course may only last
until its end; given that preprocessors mark the end of the include
file anyway (to allow the compiler to give meaningfull error messages),
this shouldn't be hard (the global name checks can even be done by
the preprocessor).
Example:
// <vector>
#pragma compiler library implementation
#ifndef _VECTOR
#define _VECTOR // no error here
namespace std
{
template<...> class vector // no error here
{
...
};
...
}
#endif
// user's header.h
// special #pragma not given
#ifndef _HEADER_H
#define _HEADER_H // error
namespace std
{
template<class T> class Foo {}; // error
}
#endif
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: David R Tribble <dtribble@technologist.com>
Date: 1999/04/21 Raw View
fvali@biotrack.com wrote:
> As I understand it, since names that contain double underscores
> are reserved, names that contain tripple or more
> underscores are reserved too, right?
Jonathan Biggar <jon@floorboard.com> wrote:
> Actually, only leading underscores at the global scope. You can
> still use leading underscores inside classes, for examples, which is
> an often used convention.
James.Kanze@dresdner-bank.com wrote:
> Leading underscores followed by an upper case letter are reserved in
> all scopes, and so cannot be used. In addition, many implementations
> seem to think that all symbols with leading underscores are reserved
> at all scoped; it is relatively frequent to find macros with a leading
> underscore followed by an lower case letter, even if the standard says
> that they shouldn't. So in the end, you may be right, but your code
> still won't compile.
Regarding names with double underscores, are they reserved in all
contexts, or just the global namespace? Can I use them in local
enum constants or typedefs, for example?
-- David R. Tribble, dtribble@technologist.com --
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: brahms@mindspring.com (Stan Brown)
Date: 1999/04/21 Raw View
Dixitque jon@floorboard.com (Jonathan Biggar) in comp.std.c++:
[about using leading underscores for variable names]
>Actually, only leading underscores at the global scope. You can still
>use leading underscores inside classes, for examples, which is an often
>used convention.
Not as I read the Standard, Jon.
17.4.3.1.2 Global names
=======================
Certain sets of names and function signatures are always reserved to the
implementation:
-- Each name that contains a double underscore (_ _) or begins with
an underscore followed by an upper-case letter (2.11) is reserved to
the implementation for any use.
-- Each name that begins with an underscore is reserved to the
implementation for use as a name in the global namespace^165
And footnote 165 reads: Such names are also reserved in namespace ::std.
[end quote from Standard]
The section head "global names" is unfortunate, because it seems only the
second clause is actually about global names. As I read the text of that
section, you may *never* use leading underscore followed by a capital
letter for your own purposes; it is *always* reserved to the
implementation. Leading underscore followed by something else is, in
theory, yours to use as long as you're not in the global namespace; but
I'll bet there are common compilers that get that wrong.
--
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA
http://www.mindspring.com/~brahms/
My reply address is correct as is. The courtesy of providing a correct
reply address is more important to me than time spent deleting spam.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Jonathan Biggar <jon@floorboard.com>
Date: 1999/04/19 Raw View
Jim Hyslop wrote:
>
> In article <7f5kc6$7o2$1@nnrp1.dejanews.com>,
> fvali@biotrack.com wrote:
> > As I understand it, since names that contain double underscores
> > are reserved, names that contain tripple or more
> > underscores are reserved too, right?
> > (Since tripple underscores contain a double underscore followed by
> > a single underscore)
> > Is this correct?
> Yep, I'm afraid so. :-)
>
> > (If it is - yuk - this means i'm going to have to do a search and replace
> > through a bunch of my headers :-( )
> Don't forget to lose leading underscores, while you're at it.
Actually, only leading underscores at the global scope. You can still
use leading underscores inside classes, for examples, which is an often
used convention.
--
Jon Biggar
Floorboard Software
jon@floorboard.com
jon@biggar.org
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James.Kanze@dresdner-bank.com
Date: 1999/04/20 Raw View
In article <371AB348.35FC324@floorboard.com>,
Jonathan Biggar <jon@floorboard.com> wrote:
> Actually, only leading underscores at the global scope. You can still
> use leading underscores inside classes, for examples, which is an often
> used convention.
Leading underscores followed by an upper case letter are reserved in all
scopes, and so cannot be used. In addition, many implementations seem
to think that all symbols with leading underscores are reserved at all
scoped; it is relatively frequent to find macros with a leading
underscore followed by an lower case letter, even if the standard says
that they shouldn't. So in the end, you may be right, but your code
still won't compile.
--
James Kanze mailto: James.Kanze@dresdner-bank.com
Conseils en informatique orient e objet/
Beratung in objekt orientierter Datenverarbeitung
Ziegelh ttenweg 17a, 60598 Frankfurt, Germany Tel. +49 (069) 63 19 86 27
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Jim Hyslop <jim.hyslop@leitch.com>
Date: 1999/04/18 Raw View
In article <7f5kc6$7o2$1@nnrp1.dejanews.com>,
fvali@biotrack.com wrote:
> As I understand it, since names that contain double underscores
> are reserved, names that contain tripple or more
> underscores are reserved too, right?
> (Since tripple underscores contain a double underscore followed by
> a single underscore)
> Is this correct?
Yep, I'm afraid so. :-)
> (If it is - yuk - this means i'm going to have to do a search and replace
> through a bunch of my headers :-( )
Don't forget to lose leading underscores, while you're at it.
--
Jim
I ignore all email from recruitment agencies.
Please do not send me email with questions - post here.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: fvali@biotrack.com
Date: 1999/04/16 Raw View
As I understand it, since names that contain double underscores
are reserved, names that contain tripple or more
underscores are reserved too, right?
(Since tripple underscores contain a double underscore followed by
a single underscore)
Is this correct?
(If it is - yuk - this means i'm going to have to do a search and replace
through a bunch of my headers :-( )
-thanks, and feel free to copy me personally on your if convenient.
-fais
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]