473,394 Members | 1,932 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,394 software developers and data experts.

leading underscore

Section 17.4.3.1.2 states that each name that begins with an underscore
is reserved to the implementation for use as a name in the global
namespace.

Exactly what defines the implementation?

Is it only narrowly defined by the compiler's internal name handling?
Or does it also include the library that comes with the compiler?
Does it include the OS library as part of the implementation?

I'm developing some portable leak tracking code, and for most functions
I can't use namespaces in the header because the code has to be able to
compile to both C and C++ source files.

I'm trying to determine what would be the best naming convention to
use, and I'm considering something like the following:
_leaktracker61_free
_leaktracker61_realloc
_leaktracker61_DumpAllLeaks
_leaktracker61_fopen
_leaktracker61_fclose

When compiled in DEBUG mode, these functions are going to be in the
global namespace, so I'm trying to limit name collision.

I'm wondering if I can consider my code as an extension to the
implementation, and there by use the leading underscore to avoid name
collision.

Nov 11 '05 #1
10 19173
Axter wrote:
Exactly what defines the implementation?

Is it only narrowly defined by the compiler's internal name handling?
Or does it also include the library that comes with the compiler?
Does it include the OS library as part of the implementation?
Yes, yes, and yes. The implementation is pretty much everything
other than code YOU are writing.

I'm wondering if I can consider my code as an extension to the
implementation, and there by use the leading underscore to avoid name
collision.


That wouldn't be portable.

Your best bet is to NOT use the underscore and hope your
long distinctive names don't collide with any in the application
under test.

Nov 11 '05 #2
Axter wrote:
Section 17.4.3.1.2 states that each name that begins with an underscore
is reserved to the implementation for use as a name in the global
namespace.

Exactly what defines the implementation?
You're the one who is reading the Standard. Doesn't it define the
'implementation'?
Is it only narrowly defined by the compiler's internal name handling?
Or does it also include the library that comes with the compiler?
What's the title of Clause 17 (from which 17.4.3.1.2 comes)?
Does it include the OS library as part of the implementation?
Doesn't it already say about that in the beginning of Clause 17?
I'm developing some portable leak tracking code, and for most functions
I can't use namespaces in the header because the code has to be able to
compile to both C and C++ source files.

I'm trying to determine what would be the best naming convention to
use, and I'm considering something like the following:
_leaktracker61_free
_leaktracker61_realloc
_leaktracker61_DumpAllLeaks
_leaktracker61_fopen
_leaktracker61_fclose
What is the reason for you to have the leading underscores? I mean, if
you simply omit them, what's going to happen?
When compiled in DEBUG mode, these functions are going to be in the
global namespace, so I'm trying to limit name collision.

I'm wondering if I can consider my code as an extension to the
implementation, and there by use the leading underscore to avoid name
collision.


It is not an extension to the implementation _unless_ you work for the
compiler vendor. Do you?

V
Nov 11 '05 #3
Axter wrote:
Section 17.4.3.1.2 states that each name that begins with an underscore
is reserved to the implementation for use as a name in the global
namespace.
My understanding is that a leading underscore is OK as long as it's not
followed by an uppercase letter. To quote from the section you cited:

"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."
I'm trying to determine what would be the best naming convention to
use, and I'm considering something like the following:
_leaktracker61_free
_leaktracker61_realloc
_leaktracker61_DumpAllLeaks
_leaktracker61_fopen
_leaktracker61_fclose


These should be OK, not because you're an "implementation" but
because the names are not reserved according to the above rules.

Nov 11 '05 #4
ni*****@microsoft.com wrote:
Axter wrote:
Section 17.4.3.1.2 states that each name that begins with an underscore
is reserved to the implementation for use as a name in the global
namespace.


My understanding is that a leading underscore is OK as long as it's not
followed by an uppercase letter. To quote from the section you cited:


Your understanding is wrong. Axter correctly quotes 17.4.3.1 of the
standard. All use of leading underscore is prohibited in the global
namespace.
Nov 11 '05 #5
Victor Bazarov wrote:
Axter wrote:
Section 17.4.3.1.2 states that each name that begins with an underscore
is reserved to the implementation for use as a name in the global
namespace.
Exactly what defines the implementation?

You're the one who is reading the Standard. Doesn't it define the
'implementation'?


If I new that, I wouldn't be asking.....
That's like someone looking for their keys, and you asking them where
was the last place they put it.
Is it only narrowly defined by the compiler's internal name handling?
Or does it also include the library that comes with the compiler?
Does it include the OS library as part of the implementation?

Doesn't it already say about that in the beginning of Clause 17?


Not that I can see.
I'm posting this question to recieve information from someone who knows
the answer.
If you don't know the answer, or you don't want to give the answer
away, then please don't bother giving me the look it up in the
dictionary answer.

Nov 11 '05 #6
Ron Natalie wrote:
Axter wrote:
Exactly what defines the implementation?

Is it only narrowly defined by the compiler's internal name handling?
Or does it also include the library that comes with the compiler?
Does it include the OS library as part of the implementation?


Yes, yes, and yes. The implementation is pretty much everything
other than code YOU are writing.

I'm wondering if I can consider my code as an extension to the
implementation, and there by use the leading underscore to avoid name
collision.


That wouldn't be portable.

Your best bet is to NOT use the underscore and hope your
long distinctive names don't collide with any in the application
under test.


Thanks.
That's what I think I will do.

I was debating which would have the higher probability of having a name
collision. IMHO, it would be less likely to have a name collision with
the implementation then with the user's code.
But I guess to make the code truely portable, it would be better to
leave the leading underscore out.

Nov 11 '05 #7
Axter wrote:
Section 17.4.3.1.2 states that each name that begins with an underscore
is reserved to the implementation for use as a name in the global
namespace.
Exactly what defines the implementation?


This is defined by the implementation.

--
Salu2
Nov 11 '05 #8
Julián Albo wrote:
Axter wrote:
Section 17.4.3.1.2 states that each name that begins with an underscore
is reserved to the implementation for use as a name in the global
namespace.
Exactly what defines the implementation?


This is defined by the implementation.


What what is... oh... uh... <stack overflow>.
Jonathan

Nov 11 '05 #9
Axter wrote:
Section 17.4.3.1.2 states that each name that begins with an
underscore is reserved to the implementation for use as a name in the
global namespace.

Exactly what defines the implementation?

It means, "not you".


Brian
Nov 11 '05 #10
Ron Natalie wrote:
ni*****@microsoft.com wrote:
Axter wrote:
Section 17.4.3.1.2 states that each name that begins with an underscore
is reserved to the implementation for use as a name in the global
namespace.


My understanding is that a leading underscore is OK as long as it's not
followed by an uppercase letter. To quote from the section you cited:


Your understanding is wrong. Axter correctly quotes 17.4.3.1 of the
standard. All use of leading underscore is prohibited in the global
namespace.


My bad. I didn't read on to the next paragraph after the one I quoted,
which deals with the global namespace.

I've never run into this since I've never had the urge to create a name
with a leading underscore at namespace scope. :-)

Nov 22 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mikael Petterson | last post by:
Hi, I got some help to go from: bbBusState to BB_BUS_STATE. However I found out :-( that the xml contained attributes like: TxDeviceGroup and that becomes:
5
by: Walter Tross | last post by:
Somebody with a very regulatory mind in this newsgroup has written that it's better not to use a leading underscore for class member names, because names with a leading underscore are used...
6
by: bobueland | last post by:
Entering >>>dir(5) I get Every time I use dir(some module) I get a lot of attributes with double underscore, for example __add__. Ok, I thought __add__ must be a method which I can apply...
16
by: Jim Langston | last post by:
I know that functions starting with an underscore, or two underscores, are reserved by the compiler/c++ and should not be used by the user and may cause undefined behavior. My question is, how...
14
by: Bit Byte | last post by:
I have the following struct: typedef struct { string symbol; string synonym; Synonym(string _synonym, string _symbol) { synonym = _synonym; symbol = _symbol; }
9
by: Joseph Turian | last post by:
Consider this code snippet which doesn't compile: struct DebugOptions { }; class Debug { public: Debug(const DebugOptions options) { _options = options; } private:
5
by: Pete C | last post by:
I was looking at Section 17.4.3.1 and I can't work out whether macro names are also covered by Section 17.4.3.1.2 ("Global names"). I often see preple chastised for using include guards like...
9
by: jbaranski | last post by:
Access 2003 on XP pro machine... i'm running a crosstab query and an export to a 3rd party company showing different benefit plans for employees; specifically dental, vision and medical pulling...
9
by: Skye | last post by:
What is this doing? print >fd, _(__doc__) I'm guessing line-splitting __doc__ into a list, but what's that leading underscore do? Thanks!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.