Boost logo

Boost :

From: Corwin Joy (cjoy_at_[hidden])
Date: 2001-06-22 19:09:18


----- Original Message -----
From: "Beman Dawes" <bdawes_at_[hidden]>
To: <boost_at_[hidden]>; <boost_at_[hidden]>
Sent: Friday, June 22, 2001 6:40 PM
Subject: Re: [boost] Question about leading underscores

> At 06:40 PM 6/22/2001, Greg Colvin wrote:
>
> >The safe rule is not to use leading underscores, although I
> >think those above are technically OK, if useless.
>
> Why? Lots of programmers (me included) use a single leading underscore in
> private member names. It never causes any problems, and is completely
> standard conforming.
>
>

The trouble with putting two underscores in a variable name is that you
might end up colliding with a preprocessor / #define macro defined by the
standard library. Since these #defines don't have scope you can't be safe
from them and so and so as noted below the standard reserves certain names
which it may replace by #define macros. Here is a related post that
appeared recently on comp.c++.moderated.

----- Original Message -----
From: "Pete Becker" <petebecker_at_[hidden]>
Newsgroups: comp.lang.c++.moderated
Sent: Monday, June 18, 2001 4:05 PM
Subject: Re: Header protection against forbidden marcos

> Attila Feher wrote:
> >
> > Hi All,
> >
> > I need some help in this trouble. As far as I know the only portable
> > way for protecting header multiply inclusion is the good-old #ifndef,
> > #define, stuff, #endif. However the C++ standard (for whatever reason)
> > reserves _all_ macros for the standard library...
>
> No, it doesn't. Basically, all names that begin with an underscore
> followed by a capital letter or by another underscore are reserved, just
> as in C (it's actually a little broader: any name containing two
> underscores is reserved, not just ones that begin with two underscores).
> Users are free to guard their headers with their own macros, and
> typically name them after the header:
>
> #ifndef Whatever_hh
> #define Whatever_hh
> // ...
> #endif
>
> --
> Pete Becker
> Dinkumware, Ltd. (http://www.dinkumware.com)
>
----- End Original Message from comp.c++.moderated-----

<..Beman continues...>
> That choice was based in an experiment some years ago trying several
> candidates (including none, trailing underscore, and some others I can't
> remember.) Leading underscore won.
>
> --Beman
>
> >17.4.3.1.2 Global names [lib.global.names]
> >
> >1 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 uppercase letter (_lex.key_) is reserved
> > to the implementation for any use.
> >
> > --Each name that begins with an underscore is reserved to the imple-
> > mentation for use as a name in the global namespace.22)
> >
> > _________________________
> > 22) Such names are also reserved in namespace ::std (_lib.re-
> > served.names_).
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk