By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,847 Members | 2,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,847 IT Pros & Developers. It's quick & easy.

reserved identifiers?

P: n/a
I know C's rules about reserved identifiers (anything starting with
"_", leading "is", etc).

I don't know C++ rules. I assume the same rules and more apply?

I've seen several conventions for member variables:

foo_
m_foo
_foo

In the case of member variables are _ prefixes still reserved?

Mar 23 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Mar 23, 2:29 pm, "Tim H" <thoc...@gmail.comwrote:
I know C's rules about reserved identifiers (anything starting with
"_", leading "is", etc).

I don't know C++ rules. I assume the same rules and more apply?

I've seen several conventions for member variables:

foo_
m_foo
_foo

In the case of member variables are _ prefixes still reserved?
Seems it is allowed.

Please refer
http://www.cplusplus.com/doc/tutorial/variables.html
Regards,
Sarath
http://sa*****@wordpress.com/

Mar 23 '07 #2

P: n/a
Sarath wrote:
On Mar 23, 2:29 pm, "Tim H" <thoc...@gmail.comwrote:
>>I know C's rules about reserved identifiers (anything starting with
"_", leading "is", etc).

I don't know C++ rules. I assume the same rules and more apply?

I've seen several conventions for member variables:

foo_
m_foo
_foo

In the case of member variables are _ prefixes still reserved?

Seems it is allowed.

Please refer
http://www.cplusplus.com/doc/tutorial/variables.html
That's not correct according to 17.3.4.1.2/2:

Each name that begins with an underscore is reserved to the
implementation for use as a name in the global namespace.

--
Ian Collins.
Mar 23 '07 #3

P: n/a
On 23 Mar, 06:29, "Tim H" <thoc...@gmail.comwrote:
I know C's rules about reserved identifiers (anything starting with
"_", leading "is", etc).

I don't know C++ rules. I assume the same rules and more apply?

I've seen several conventions for member variables:

foo_
m_foo
_foo

In the case of member variables are _ prefixes still reserved?
Any name beginning with a double underscore or an underscore followed
by an uppercase letter is reserved for any use, in short, don't use.
Any name beginning with an underscore is reserved for use in the
global namespace, meaning be careful.

Personally I put an underscore at the end of the names of members but
I'm sure you can find a lot of other practices, all (probably) equally
good as long as they don't do something illegal.

--
Erik Wikström

Mar 23 '07 #4

P: n/a

On 3/23/07 12:30 AM, in article 56**************@mid.individual.net, "Ian
Collins" <ia******@hotmail.comwrote:
Sarath wrote:
>On Mar 23, 2:29 pm, "Tim H" <thoc...@gmail.comwrote:
>>I know C's rules about reserved identifiers (anything starting with
"_", leading "is", etc).

I don't know C++ rules. I assume the same rules and more apply?

I've seen several conventions for member variables:

foo_
m_foo
_foo

In the case of member variables are _ prefixes still reserved?

Seems it is allowed.

Please refer
http://www.cplusplus.com/doc/tutorial/variables.html
That's not correct according to 17.3.4.1.2/2:

Each name that begins with an underscore is reserved to the
implementation for use as a name in the global namespace.
In other words, names that begin with a leading underscore and that are not
in the global namespace are available as names for the program to use. And
since the names of member variables are names in the scope of the class that
defines them - they are not names in the global namespace itself. So a
program is free to use a name with a (single) leading underscore as the name
of a class member. Nevertheless, to keep things simple it is probably a good
idea for a program not to use a name with a leading underscore anywhere -
even when it may be OK to do so.

Greg

Mar 23 '07 #5

P: n/a
On 23 Mar, 07:46, Greg Herlihy <gre...@pacbell.netwrote:
On 3/23/07 12:30 AM, in article 56he0hF28b9qj...@mid.individual.net, "Ian

Collins" <ian-n...@hotmail.comwrote:
Sarath wrote:
On Mar 23, 2:29 pm, "Tim H" <thoc...@gmail.comwrote:
>I know C's rules about reserved identifiers (anything starting with
"_", leading "is", etc).
>I don't know C++ rules. I assume the same rules and more apply?
>I've seen several conventions for member variables:
>foo_
m_foo
_foo
>In the case of member variables are _ prefixes still reserved?
Seems it is allowed.
Please refer
http://www.cplusplus.com/doc/tutorial/variables.html
That's not correct according to 17.3.4.1.2/2:
Each name that begins with an underscore is reserved to the
implementation for use as a name in the global namespace.

In other words, names that begin with a leading underscore and that are not
in the global namespace are available as names for the program to use. And
since the names of member variables are names in the scope of the class that
defines them - they are not names in the global namespace itself. So a
program is free to use a name with a (single) leading underscore as the name
of a class member.
Not quite. As Erik Wikström says elsethread, names beginning with a
leading underscore followed by an uppercase letter are reserved for
the implementation for any use. So, Because member variables are not
in the global namespace, _Member is an illegal name for a member
variable whereas _member is not. _Global and _global are both illegal
names in the global namespace.

Also not mentioned yet, names containing a double underscore anywhere
in the name are reserved for the implementation for any use.
Nevertheless, to keep things simple it is probably a good
idea for a program not to use a name with a leading underscore anywhere -
even when it may be OK to do so.
Agreed. And the same for names containing a double underscore. I know
what the rules are and I know where to look them up to remind myself
if I forget (mainly because this question arises here every so often).
But I see no advantage in demonstrating in code how clever I am by
allowing myself to use leading underscores where they are legal. Far
simpler to just avoid leading underscores and double underscores
completely (and I don't find that restriction causes me any difficulty
at all).

Gavin Deane

Mar 23 '07 #6

P: n/a
Tim H <th*****@gmail.comwrote:
I know C's rules about reserved identifiers (anything starting with
"_", leading "is", etc).

I don't know C++ rules. I assume the same rules and more apply?
I found this (no longer maintained) page:
http://web.archive.org/web/200404160...h/cppredef.htm
I've seen several conventions for member variables:

foo_
m_foo
_foo

In the case of member variables are _ prefixes still reserved?
Others have answered this. My personal convention is to use the
trailing underscore.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Mar 23 '07 #7

P: n/a
Erik Wikström wrote:
On 23 Mar, 06:29, "Tim H" <thoc...@gmail.comwrote:
>I know C's rules about reserved identifiers (anything starting with
"_", leading "is", etc).

I don't know C++ rules. I assume the same rules and more apply?

I've seen several conventions for member variables:

foo_
m_foo
_foo

In the case of member variables are _ prefixes still reserved?

Any name beginning with a double underscore or an underscore followed
by an uppercase letter is reserved for any use, in short, don't use.
Any name beginning with an underscore is reserved for use in the
global namespace, meaning be careful.
Also according to 17.3.4.1.2/2 footnote 165, leading underscore
identifiers are reserved in the std:: namespace as well.
Mar 23 '07 #8

P: n/a
red floyd wrote:
Erik Wikström wrote:
>On 23 Mar, 06:29, "Tim H" <thoc...@gmail.comwrote:
>>I know C's rules about reserved identifiers (anything starting with
"_", leading "is", etc).

I don't know C++ rules. I assume the same rules and more apply?

I've seen several conventions for member variables:

foo_
m_foo
_foo

In the case of member variables are _ prefixes still reserved?

Any name beginning with a double underscore or an underscore followed
by an uppercase letter is reserved for any use, in short, don't use.
Any name beginning with an underscore is reserved for use in the
global namespace, meaning be careful.

Also according to 17.3.4.1.2/2 footnote 165, leading underscore
identifiers are reserved in the std:: namespace as well.
Of course, with the exception of template specializations, the *entire*
std:: namespace is reserved.
Mar 23 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.