leading underscore

A

Axter

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.
 
R

Ron Natalie

Axter said:
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.
 
V

Victor Bazarov

Axter said:
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
 
N

niklasb

Axter said:
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.
 
R

Ron Natalie

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.
 
A

Axter

Victor said:
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.
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.
 
A

Axter

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



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.
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

Axter said:
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.
 
D

Default User

Axter said:
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
 
N

niklasb

Ron said:
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. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top