473,382 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

reserved identifiers?

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
8 3332
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
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
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

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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Lawrence Oluyede | last post by:
Does it worth to make "object" keyword a reserved one? I'd like to avoid oddities like this: Python 2.3c1 (#44, Jul 18 2003, 14:32:36) on win32 Type "help", "copyright", "credits" or "license"...
12
by: Michael Foord | last post by:
Here's a little oddity with 'print' being a reserved word... >>> class thing: pass >>> something = thing() >>> something.print = 3 SyntaxError: invalid syntax >>> print something.__dict__...
2
by: Matthew Cascio | last post by:
My understanding is that using reserved words as column names is allowable as long as they are quoted. I am trying to create a table dynamically with columns defined by the first row of a text...
9
by: Nick Wedd | last post by:
I am having trouble (using IE6, with Windows), in using certain ids for my html elements. id="c" works fine. So do most one-letter ids. But id="i", and id="p", seem not to work. I don't...
3
by: VK | last post by:
Just to realease my frustration: innocent "enum" is a reserved word in JScript! !@#$%^&* I occasionally discovered it just before I got ready to smash my computer over my head (some people...
31
by: metaperl | last post by:
-- python -i File "<stdin>", line 1 class = "algebra" ^ SyntaxError: invalid syntax Why isn' t the parser smart enough to see that class followed by an identifier is used for class...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
4
by: Bas Wassink | last post by:
Hello all, I've been wondering about struct member names and reserved identifiers for some time now and I can't figure out whether the reserved identifier restrictions apply to struct members. ...
0
by: Gordon Burditt | last post by:
>----------------------------- 8< ---------------------------------- Not if you include <string.h>, in which case the second paragraph above is an issue. Otherwise, it's OK. It's OK, but I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.