 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
BRIAN VICKERY Guest
|
Posted: Fri Jan 30, 2004 3:28 pm Post subject: underscores in class member names |
|
|
I've heard that some compilers reserve the '_' starting a symbol for system
variables/symbols. I can not find this documented anywhere (so far). I've
used an '_' at the end of member variables (ie. Uint16 bar_; ) to
distinquish private fields, but this does not stand out as much as if the
'_' were at the begginning of the name as in the following class
declaration.
class Foo {
private:
Uint16 _baz;
Uint32 _bar;
public:
....
};
|
|
| Back to top |
|
 |
Rolf Magnus Guest
|
Posted: Fri Jan 30, 2004 3:29 pm Post subject: Re: underscores in class member names |
|
|
BRIAN VICKERY wrote:
| Quote: | I've heard that some compilers reserve the '_' starting a symbol for
system variables/symbols.
|
The C++ language reserves some of them, like e.g. those that begin with
an underscore followed by an uppercase letter and those that contain
two consecutive underscores.
| Quote: | I can not find this documented anywhere (so far).
I've used an '_' at the end of member variables (ie. Uint16 bar_; )
to distinquish private fields,
|
That's quite common practise.
| Quote: | but this does not stand out as much as if the '_' were at the
begginning of the name as in the following class
declaration.
class Foo {
private:
Uint16 _baz;
Uint32 _bar;
public:
....
};
|
I think those shold be fine.
|
|
| Back to top |
|
 |
Sumit Rajan Guest
|
Posted: Fri Jan 30, 2004 3:50 pm Post subject: Re: underscores in class member names |
|
|
"BRIAN VICKERY" <islandhaole (AT) verizon (DOT) net> wrote
| Quote: | I've heard that some compilers reserve the '_' starting a symbol for
system
variables/symbols. I can not find this documented anywhere (so far).
I've
used an '_' at the end of member variables (ie. Uint16 bar_; ) to
distinquish private fields, but this does not stand out as much as if the
'_' were at the begginning of the name as in the following class
declaration.
class Foo {
private:
Uint16 _baz;
Uint32 _bar;
public:
....
};
|
From 17.4.3.1.2 of the Standard:
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 (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.
|
|
| Back to top |
|
 |
Rob Williscroft Guest
|
Posted: Fri Jan 30, 2004 3:51 pm Post subject: Re: underscores in class member names |
|
|
BRIAN VICKERY wrote in news:LKuSb.110$9p5.82 (AT) nwrddc02 (DOT) gnilink.net:
| Quote: | I've heard that some compilers reserve the '_' starting a symbol for
system variables/symbols. I can not find this documented anywhere (so
far). I've used an '_' at the end of member variables (ie. Uint16
bar_; ) to distinquish private fields, but this does not stand out as
much as if the '_' were at the begginning of the name as in the
following class declaration.
class Foo {
private:
Uint16 _baz;
Uint32 _bar;
public:
....
};
|
Am identifier with single leading undersore is reserved for the
implementation if:
Its followed by an uppercase letter (anywhere).
Its followed by another underscore (anywhere), in fact *all* identifiers
that *contain* 2 or more *consecutive* underscores are reserved.
Its declared at global namespace scope, i.e its a macro or it
*isn't* declared within an namespace, class, struct or union or it
*isn't* a paramiter name or a local variable name.
Also IIUC it shouldn't be a declared extern "C".
So you usage for member identifiers is Ok.
Nobody really likes it though and most people can't be bothered to
remember all the rules, so they will probably complain that your using a
reserved identifier anyway, so I'd suggest m_baz or some such thing.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
|
|
| Back to top |
|
 |
Jonathan Turkanis Guest
|
Posted: Fri Jan 30, 2004 8:10 pm Post subject: Re: underscores in class member names |
|
|
"Rob Williscroft" <rtw (AT) freenet (DOT) REMOVE.co.uk> wrote in message:
| Quote: |
Am identifier with single leading undersore is reserved for the
implementation if:
Its followed by an uppercase letter (anywhere).
Its followed by another underscore (anywhere), in fact *all*
identifiers
that *contain* 2 or more *consecutive* underscores are reserved.
Its declared at global namespace scope, i.e its a macro or it
*isn't* declared within an namespace, class, struct or union or it
*isn't* a paramiter name or a local variable name.
Also IIUC it shouldn't be a declared extern "C".
So you usage for member identifiers is Ok.
Nobody really likes it though and most people can't be bothered to
remember all the rules, so they will probably complain that your
using a
reserved identifier anyway, so I'd suggest m_baz or some such thing.
|
I'm familiar with the language from the standard, but it sounds a bit
ambiguous:
"reserved to the implementation for use as a name in the global
namespace"
could mean:
(i) reserved to the implementation; also, must be global,
or
(ii) reserved to the implementation if used in the global namespace
Why do you prefer (i)? Is this known to be the correct interpretation?
Jonathan
|
|
| Back to top |
|
 |
Jonathan Turkanis Guest
|
Posted: Fri Jan 30, 2004 8:11 pm Post subject: Re: underscores in class member names |
|
|
"Jonathan Turkanis" <technews (AT) kangaroologic (DOT) com> wrote
| Quote: |
Why do you prefer (i)? Is this known to be the correct
interpretation? |
I meant (ii) here.
Jonathan
|
|
| Back to top |
|
 |
Bob Hairgrove Guest
|
Posted: Fri Jan 30, 2004 8:27 pm Post subject: Re: underscores in class member names |
|
|
On Fri, 30 Jan 2004 16:29:49 +0100, Rolf Magnus <ramagnus (AT) t-online (DOT) de>
wrote:
| Quote: | BRIAN VICKERY wrote:
I've heard that some compilers reserve the '_' starting a symbol for
system variables/symbols.
|
Check 17.4.3.1.2 of the C++ standard first.
Stroustrup says "never" ... (see p. 81 of the 3rd edition, "The C++
Programming Language).
--
Bob Hairgrove
[email]NoSpamPlease (AT) Home (DOT) com[/email]
|
|
| Back to top |
|
 |
Rob Williscroft Guest
|
Posted: Fri Jan 30, 2004 11:36 pm Post subject: Re: underscores in class member names |
|
|
Jonathan Turkanis wrote in news:bved3v$q8s8r$1 (AT) ID-216073 (DOT) news.uni-
berlin.de:
| Quote: | So you usage for member identifiers is Ok.
Nobody really likes it though and most people can't be bothered to
remember all the rules, so they will probably complain that your
using a
reserved identifier anyway, so I'd suggest m_baz or some such thing.
I'm familiar with the language from the standard, but it sounds a bit
ambiguous:
"reserved to the implementation for use as a name in the global
namespace"
could mean:
(i) reserved to the implementation; also, must be global,
|
This would be the same as reserved ... everywhere. The "must be global"
would be unnessasery additional info'.
| Quote: | or
(ii) reserved to the implementation if used in the global namespace
|
[from elswhere]
| Quote: | I meant (ii) here.
Why do you prefer (i)? Is this known to be the correct interpretation?
|
Sorry but (i) doesn't make any sense to me.
_lowecase identifiers are used to support the C standard library and
meny C++ implementation's just use the C library as-is, and most
allow you to link with C code that will link in the C library.
C++ needs another set of identifiers _Uppercase so it doesn't stomp
on the _lowecase ones and also the double underscore rule for name
mangaling. This allows a C++ compiler to compile via a C compiler
as meny still do.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
|
|
| Back to top |
|
 |
Graham Dumpleton Guest
|
Posted: Sat Jan 31, 2004 12:24 am Post subject: Re: underscores in class member names |
|
|
Rob Williscroft <rtw (AT) freenet (DOT) REMOVE.co.uk> wrote
| Quote: | BRIAN VICKERY wrote in news:LKuSb.110$9p5.82 (AT) nwrddc02 (DOT) gnilink.net:
I've heard that some compilers reserve the '_' starting a symbol for
system variables/symbols. I can not find this documented anywhere (so
far). I've used an '_' at the end of member variables (ie. Uint16
bar_; ) to distinquish private fields, but this does not stand out as
much as if the '_' were at the begginning of the name as in the
following class declaration.
class Foo {
private:
Uint16 _baz;
Uint32 _bar;
public:
....
};
Am identifier with single leading undersore is reserved for the
implementation if:
Its followed by an uppercase letter (anywhere).
|
From memory, Microsoft C++ used to (not sure now), define a special
keyword called "_except". If you tried to use that name, even as a
member variable of a class, the compiler would spit the dummy.
Thus, regardless of what the standard for C++ says, don't necessarily
expect Microsoft to adhere to it. :-)
|
|
| Back to top |
|
 |
Rob Williscroft Guest
|
Posted: Sat Jan 31, 2004 1:35 am Post subject: Re: underscores in class member names |
|
|
Graham Dumpleton wrote in news:dc6f5c99.0401301624.544b4b2
@posting.google.com:
| Quote: |
From memory, Microsoft C++ used to (not sure now), define a special
keyword called "_except". If you tried to use that name, even as a
member variable of a class, the compiler would spit the dummy.
|
yes also things like _far, _near, _try all of which are extemsion
keywords
| Quote: | Thus, regardless of what the standard for C++ says, don't necessarily
expect Microsoft to adhere to it. :-)
|
Well did MS introduce the keyword before or after the standard
came out (1998). Certainly I've noticed that all of the extension
keywords I've come accross reciently have had 2 leading underscores
__declspec.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
|
|
| Back to top |
|
 |
Jonathan Turkanis Guest
|
Posted: Sat Jan 31, 2004 2:03 am Post subject: Re: underscores in class member names |
|
|
"Rob Williscroft" <rtw (AT) freenet (DOT) REMOVE.co.uk> wrote in message:
| Quote: |
"reserved to the implementation for use as a name in the
global
namespace"
could mean:
(i) reserved to the implementation; also, must be global,
This would be the same as reserved ... everywhere. The "must be
global"
would be unnessasery additional info'.
|
Unnecessary info for users, maybe, but not for implementers.
Maybe you mean it would be an 'unneccessary additional restriction'?
Are you sure that C++ doesn't have any of these? ;-)
Jonathan
|
|
| Back to top |
|
 |
Rob Williscroft Guest
|
Posted: Sat Jan 31, 2004 2:16 am Post subject: Re: underscores in class member names |
|
|
Jonathan Turkanis wrote in news:bvf1qq$s3oii$1 (AT) ID-216073 (DOT) news.uni-
berlin.de:
| Quote: |
"Rob Williscroft" <rtw (AT) freenet (DOT) REMOVE.co.uk> wrote in message:
"reserved to the implementation for use as a name in the
global
namespace"
could mean:
(i) reserved to the implementation; also, must be global,
This would be the same as reserved ... everywhere. The "must be
global"
would be unnessasery additional info'.
Unnecessary info for users, maybe, but not for implementers.
|
How would it help an implementer, the standard tells implementors
what they have to implement not *how*, "must be global" could
only be related to how.
| Quote: |
Maybe you mean it would be an 'unneccessary additional restriction'?
|
It isn't a restriction, its saying that _lowercase *must* be a global
namespace identifier, i.e. its telling an implementor some details
about *how* to implement.
[snip]
Rob.
--
http://www.victim-prime.dsl.pipex.com/
|
|
| Back to top |
|
 |
Jonathan Turkanis Guest
|
Posted: Sat Jan 31, 2004 2:38 am Post subject: Re: underscores in class member names |
|
|
"Rob Williscroft" <rtw (AT) freenet (DOT) REMOVE.co.uk> wrote in message:
| Quote: | This would be the same as reserved ... everywhere. The "must be
global"
would be unnessasery additional info'.
Unnecessary info for users, maybe, but not for implementers.
How would it help an implementer, the standard tells implementors
what they have to implement not *how*, "must be global" could
only be related to how.
|
Did I say 'helpful'? I said 'necessary': if (i) is correct, then it
constitutes necessary information for implementers.
| Quote: |
Maybe you mean it would be an 'unneccessary additional
restriction'?
It isn't a restriction, its saying that _lowercase *must* be a
global
namespace identifier, i.e. its telling an implementor some details
about *how* to implement.
|
What distinction are you trying to make? I don't see how a requirement
that such identifiers -- if used by an implementation -- must be
global, isn't a restriction. True, the standard tries to give
implementers broad discretion, yet it also puts quite a few
constraints on implementations.
Maybe you should try to find some evidence in favor of your
interpretation. I never said it was wrong, by the way. I just asked
you to support it.
Jonathan
|
|
| Back to top |
|
 |
Rob Williscroft Guest
|
Posted: Sat Jan 31, 2004 3:58 am Post subject: Re: underscores in class member names |
|
|
Jonathan Turkanis wrote in news:bvf3rp$rl73d$1 (AT) ID-216073 (DOT) news.uni-
berlin.de:
| Quote: |
"Rob Williscroft" <rtw (AT) freenet (DOT) REMOVE.co.uk> wrote in message:
This would be the same as reserved ... everywhere. The "must be
global"
would be unnessasery additional info'.
Unnecessary info for users, maybe, but not for implementers.
How would it help an implementer, the standard tells implementors
what they have to implement not *how*, "must be global" could
only be related to how.
Did I say 'helpful'? I said 'necessary': if (i) is correct, then it
constitutes necessary information for implementers.
|
My apologees, I should have consulted the standard when you first said:
| Quote: |
I'm familiar with the language from the standard, but it sounds a bit
ambiguous:
"reserved to the implementation for use as a name in the global
namespace"
could mean:
(i) reserved to the implementation; also, must be global,
|
This section (17.4.3) is describing constraints on programmes.
However your rewording with hindsight appears to be as if your reading
the section as constraining implementation's.
| Quote: |
Maybe you mean it would be an 'unneccessary additional
restriction'?
It isn't a restriction, its saying that _lowercase *must* be a
global
namespace identifier, i.e. its telling an implementor some details
about *how* to implement.
What distinction are you trying to make? I don't see how a requirement
that such identifiers -- if used by an implementation -- must be
global, isn't a restriction.
|
Indeed, implementors arn't allowed to use _lowercase identifiers
other than in the global namespace (or in std).
I interpreted you originaly as suggesting *nobody* could use such
identifiers other than in the global namespace and only
implementors can use them there.
| Quote: | True, the standard tries to give
implementers broad discretion, yet it also puts quite a few
constraints on implementations.
Maybe you should try to find some evidence in favor of your
interpretation. I never said it was wrong, by the way. I just asked
you to support it.
|
There is only one peice evidence available, I presume since you
quoted from it, that you've read it. It helps if you read the all
of "17.4.3 Constraints on programs", here's the relevent quote:
17.4.3.1.2 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 (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)
165) Such names are also reserved in namespace ::std (17.4.3.1).
The second bullet is clearly saying that implementation's can use
identifiers such as _lowercase at in the global namespace so
a conforming programme may not.
The note 165) tells us we can't put such identifiers in namespace std
but we can't do that anyway.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
|
|
| Back to top |
|
 |
Jack Klein Guest
|
Posted: Sat Jan 31, 2004 4:20 am Post subject: Re: underscores in class member names |
|
|
On Fri, 30 Jan 2004 13:10:19 -0700, "Jonathan Turkanis"
<technews (AT) kangaroologic (DOT) com> wrote in comp.lang.c++:
| Quote: |
"Rob Williscroft" <rtw (AT) freenet (DOT) REMOVE.co.uk> wrote in message:
Am identifier with single leading undersore is reserved for the
implementation if:
Its followed by an uppercase letter (anywhere).
Its followed by another underscore (anywhere), in fact *all*
identifiers
that *contain* 2 or more *consecutive* underscores are reserved.
Its declared at global namespace scope, i.e its a macro or it
*isn't* declared within an namespace, class, struct or union or it
*isn't* a paramiter name or a local variable name.
Also IIUC it shouldn't be a declared extern "C".
So you usage for member identifiers is Ok.
Nobody really likes it though and most people can't be bothered to
remember all the rules, so they will probably complain that your
using a
reserved identifier anyway, so I'd suggest m_baz or some such thing.
I'm familiar with the language from the standard, but it sounds a bit
ambiguous:
"reserved to the implementation for use as a name in the global
namespace"
could mean:
(i) reserved to the implementation; also, must be global,
or
(ii) reserved to the implementation if used in the global namespace
Why do you prefer (i)? Is this known to be the correct interpretation?
Jonathan
|
Your confusion, and this wording, is caused by C++ adopting a C
restriction but applying new terminology.
C reserves the leading underscore+upper case, and leading double
underscore (but not embedded double underscore, that's a C++ addition)
in all contexts.
Then it reserves leading underscore+lower case at file scope. The
problem with C++ duplicating this restriction is... there is NO SUCH
THING as "file scope" in the standard C++. The phrase literally does
not exist in the standard.
What is file scope in C has been expanded into the concept of
namespace scope in C++. Things that are defined or declared outside
of a function in C++ are either inside a (named or anonymous)
namespace, concepts that do not exist in C, or they are at the top
level, what C calls "file scope" and C++ calls the global namespace.
Note that it makes no difference whether the "file scope"/"global
namespace" identifiers have external linkage or not, even with
internal linkage they can conflict with things the compiler defines in
its header files, or even pre-defined helper functions that it calls
directly.
Don't confuse the global namespace in C++ with the concept of global
variables. It really means pretty much exactly the same thing as file
scope in C.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
|
|
| Back to top |
|
 |
|
|
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
|
|