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

leading underscore

P: n/a
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
Share this Question
Share on Google+
10 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.