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

underscore names

ok
I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that names
starting with underscores are reserved for the implementation. I decided not
to because it would make me look like somebody who just wastes other
people's time instead of finding real bugs.
Come on, how serious should we take this rule? This wont ever be an issue
Mar 1 '06 #1
19 3283
ok wrote:
I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that
names starting with underscores are reserved for the implementation. I
decided not to because it would make me look like somebody who just
wastes other people's time instead of finding real bugs.
Come on, how serious should we take this rule?
Very serious(ly)!
This wont ever be an issue


It is, and a big one at that. C&V 7.1.3p1:

Each header declares or defines all identifiers listed in its associated
subclause, and optionally declares or defines identifiers listed in its
associated future library directions subclause and identifiers which are
always reserved either for any use or for use as file scope identifiers.

— All identifiers that begin with an underscore and either an uppercase
letter or another underscore are always reserved for any use.
— All identifiers that begin with an underscore are always reserved for
use as identifiers with file scope in both the ordinary and tag name
spaces.

PS
Are you sure you're not trolling?

--
BR, Vladimir

You definitely intend to start living sometime soon.

Mar 1 '06 #2
> I started thinking a bit if I should tell the author of that code that names
starting with underscores are reserved for the implementation.


I think that the convention about names says that names starting with
underscores and with the first non-underscore letter capitalized are
reserved for the implementation of the C library. I saw a suggestion
made by P.J. Plauger on his book "STD C Library".

Particularly I avoid naming variables with underscores as first
characters because I had problems in the past with Tru64 C library
implementation. However I'm not sure if you should worry about it. A
lot of people use underscores to start names they consider "internal"
and are not intended to be exported.

Mar 1 '06 #3


ok wrote On 03/01/06 13:13,:
I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that names
starting with underscores are reserved for the implementation. I decided not
to because it would make me look like somebody who just wastes other
people's time instead of finding real bugs.
Come on, how serious should we take this rule? This wont ever be an issue


You are *so* right! Down with the pedants! Just for
the sake of interest, though, would you try the following
program on your system and tell us what the output is?

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <inttypes.h>
#include <iso646.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>

int __EXTENSIONS__ = __LINE__;
int __MATHERR_ERRNO_DONTCARE = __LINE__;
int __P = __LINE__;
int __PRAGMA_REDEFINE_EXTNAME = __LINE__;
int ___errno = __LINE__;
int __assert = __LINE__;
int __buf = __LINE__;
int __filbuf = __LINE__;
int __flsbuf = __LINE__;
int __flt_rounds = __LINE__;
int __fltrounds = __LINE__;
int __i386 = __LINE__;
int __ia64 = __LINE__;
int __lint = __LINE__;
int __longlong_t = __LINE__;
int __posix_asctime_r = __LINE__;
int __posix_ctime_r = __LINE__;
int __posix_sigwait = __LINE__;
int __setp = __LINE__;
int __sigev_pad2 = __LINE__;
int __signo = __LINE__;
int __sparc = __LINE__;
int __strptime_dontzero = __LINE__;
int __time = __LINE__;
int __tm = __LINE__;
int __va_list = __LINE__;

#define SHOW(x) printf("%s == %d\n", STRING(x), x);

int main(void)
{
SHOW(__EXTENSIONS__);
SHOW(__MATHERR_ERRNO_DONTCARE);
SHOW(__P);
SHOW(__PRAGMA_REDEFINE_EXTNAME);
SHOW(___errno);
SHOW(__assert);
SHOW(__buf);
SHOW(__filbuf);
SHOW(__flsbuf);
SHOW(__flt_rounds);
SHOW(__fltrounds);
SHOW(__i386);
SHOW(__ia64);
SHOW(__lint);
SHOW(__longlong_t);
SHOW(__posix_asctime_r);
SHOW(__posix_ctime_r);
SHOW(__posix_sigwait);
SHOW(__setp);
SHOW(__sigev_pad2);
SHOW(__signo);
SHOW(__sparc);
SHOW(__strptime_dontzero);
SHOW(__time);
SHOW(__tm);
SHOW(__va_list);
return 0;
}
--
Er*********@sun.com

Mar 1 '06 #4
In article <du**********@news1brm.Central.Sun.COM>,
Eric Sosman <Er*********@sun.com> wrote:
You are *so* right! Down with the pedants! Just for
the sake of interest, though, would you try the following
program on your system and tell us what the output is? #define SHOW(x) printf("%s == %d\n", STRING(x), x);


You don't define STRING(x)
--
Prototypes are supertypes of their clones. -- maplesoft
Mar 1 '06 #5
ok wrote:
I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that names
starting with underscores are reserved for the implementation. I decided not
to because it would make me look like somebody who just wastes other
people's time instead of finding real bugs.
Come on, how serious should we take this rule? This wont ever be an issue

After spending/wasting a day debugging a largish tool that managed to
define
_sys_read, which on one OS clashed with an actual system function which
even the dynamic loader ended up in - failing to load the app, debugger
provided nothing meaningfull etc etc:
Just don't ever do it.

Especially when you know you shouldn't do it.

Mar 1 '06 #6

"Eric Sosman" <Er*********@sun.com> wrote in message
news:du**********@news1brm.Central.Sun.COM...


ok wrote On 03/01/06 13:13,:
I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that
names
starting with underscores are reserved for the implementation. I decided
not
to because it would make me look like somebody who just wastes other
people's time instead of finding real bugs.
Come on, how serious should we take this rule? This wont ever be an issue


You are *so* right! Down with the pedants! Just for
the sake of interest, though, would you try the following
program on your system and tell us what the output is?

-snip code

Won't compile. I get the following "fatal error C1083: Cannot open include
file: 'inttypes.h': No such file or directory."
Is inttypes.h a standard header?
--
MrG{DRGN}
Mar 1 '06 #7
On Wed, 01 Mar 2006 19:42:12 GMT, "MrG{DRGN}" <Ia****@here.com> wrote:

"Eric Sosman" <Er*********@sun.com> wrote in message
news:du**********@news1brm.Central.Sun.COM...


ok wrote On 03/01/06 13:13,:
I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that
names
starting with underscores are reserved for the implementation. I decided
not
to because it would make me look like somebody who just wastes other
people's time instead of finding real bugs.
Come on, how serious should we take this rule? This wont ever be an issue


You are *so* right! Down with the pedants! Just for
the sake of interest, though, would you try the following
program on your system and tell us what the output is?

-snip code

Won't compile. I get the following "fatal error C1083: Cannot open include
file: 'inttypes.h': No such file or directory."
Is inttypes.h a standard header?


Yes, in C99.

--
Al Balmer
Sun City, AZ
Mar 1 '06 #8
ok said:
I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that
names starting with underscores are reserved for the implementation. I
decided not to because it would make me look like somebody who just wastes
other people's time instead of finding real bugs.
Please stop wasting other people's time, and go fix the real bug you just
found.
Come on, how serious should we take this rule? This wont ever be an issue


....except when it becomes an issue.

If you stay the hell out of implementation namespace, you eliminate one
possible cause of bugs. Isn't that a good thing?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 1 '06 #9
Richard Heathfield <in*****@invalid.invalid> writes:
ok said:
I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that
names starting with underscores are reserved for the implementation. I
decided not to because it would make me look like somebody who just wastes
other people's time instead of finding real bugs.


Please stop wasting other people's time, and go fix the real bug you just
found.


He said it's in somebody else's code; he may not be in a position to
fix it.

If the code in question is part of the implementation, there's no
problem. If it isn't, using an identifier starting with "__" is
unsafe -- but in practice, it's *probably* only going to be a problem
if the code is used with an implementation that happens to use that
specific identifier.

To the OP: sure, go ahead and notify the author; that would have been
just as easy as notifying the rest of us.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 1 '06 #10
Keith Thompson wrote:
Richard Heathfield <in*****@invalid.invalid> writes:
ok said:
I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code
that names starting with underscores are reserved for the
implementation. I decided not to because it would make me look like
somebody who just wastes other people's time instead of finding real
bugs.


Please stop wasting other people's time, and go fix the real bug you
just found.


He said it's in somebody else's code; he may not be in a position to
fix it.

If the code in question is part of the implementation, there's no
problem. If it isn't, using an identifier starting with "__" is
unsafe -- but in practice, it's *probably* only going to be a problem
if the code is used with an implementation that happens to use that
specific identifier.

To the OP: sure, go ahead and notify the author; that would have been
just as easy as notifying the rest of us.


Not to mention that it may have fixed or prevented a possibly nasty bug.

--
BR, Vladimir

It is easier to make a saint out of a libertine than out of a prig.
-- George Santayana

Mar 1 '06 #11
Richard Heathfield <in*****@invalid.invalid> writes:
If you stay the hell out of implementation namespace, you eliminate one
possible cause of bugs. Isn't that a good thing?


Namespace issues are a problem no matter what you do. I searched
for gc_context (similar to the OP's identifier) online and found
two classes of results: those related to garbage collection in a
Lisp implementation and those related to drawing in a graphics
context. If I wanted to modify the Lisp implementation to
natively support graphics, I could conceivably run into trouble.

However, I agree that starting an identifier with _ is usually a
bad idea. There's a gray area in writing software that you mean
to integrate into a implementation, of course.
--
"The expression isn't unclear *at all* and only an expert could actually
have doubts about it"
--Dan Pop
Mar 1 '06 #12

"Vladimir S. Oka" <no****@btopenworld.com> wrote in message
news:du**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
Keith Thompson wrote:
Richard Heathfield <in*****@invalid.invalid> writes:
ok said:
I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code
that names starting with underscores are reserved for the
implementation. I decided not to because it would make me look like
somebody who just wastes other people's time instead of finding real
bugs.


Not to mention that it may have fixed or prevented a possibly nasty bug.

Not so much a bug as a nuisance.
What will happen is that some compiler will choke on the leading
underscores, but you will be able to coax it into compiling by
specifying --stripped_export or something to the linker. The instructions
for building will gradually become more and more complex until one day the
whole thing refuses to compile at all without getting an expert in that
particular operating system in to set things up.
--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $6.90 paper, available www.lulu.com
Mar 1 '06 #13


Walter Roberson wrote On 03/01/06 14:30,:
In article <du**********@news1brm.Central.Sun.COM>,
Eric Sosman <Er*********@sun.com> wrote:
You are *so* right! Down with the pedants! Just for
the sake of interest, though, would you try the following
program on your system and tell us what the output is?


#define SHOW(x) printf("%s == %d\n", STRING(x), x);

You don't define STRING(x)


Just trying to make sure it wouldn't compile ...

(I actually ran the awful source through a compiler,
which got so thoroughly bollixed that it never got around
to pointing out my misteak -- the non-intentional one,
that is.)

--
Er*********@sun.com

Mar 1 '06 #14
On Wed, 01 Mar 2006 19:42:12 GMT, in comp.lang.c , "MrG{DRGN}"
<Ia****@here.com> wrote:
Is inttypes.h a standard header?


Yes, but you'll need a recent standards-compliant compiler to provide
it.

7.8 Format conversion of integer types <inttypes.h>
1 The header <inttypes.h> includes the header <stdint.h> and extends
it with additional facilities provided by hosted implementations.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Mar 1 '06 #15
ok wrote:

I came across some variable name like __gc_context. I started
thinking a bit if I should tell the author of that code that names
starting with underscores are reserved for the implementation. I
decided not to because it would make me look like somebody who
just wastes other people's time instead of finding real bugs.
Come on, how serious should we take this rule? This wont ever be
an issue


Oh yes it will. The implementation needs a namespace to play in,
and using such things can totally foul up your system. A very
likely candidate is __file or _file.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
Mar 2 '06 #16
ok

"ok" <la@hm.com> wrote in message
news:du**********@news2.zwoll1.ov.home.nl...
I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that
names starting with underscores are reserved for the implementation. I
decided not to because it would make me look like somebody who just wastes
other people's time instead of finding real bugs.
Come on, how serious should we take this rule? This wont ever be an issue


I think you all misunderstood me. I know this rule, so its pretty easy to
avoid using them myself.
The question was more is it worth going on a holy crusade and make me look
like a fool who worries too much about C instead of writing software. I did
ask a few coworkers and funnily they all said no I wouldnt tell :)
Mar 2 '06 #17


ok wrote On 03/02/06 12:47,:
"ok" <la@hm.com> wrote in message
news:du**********@news2.zwoll1.ov.home.nl...
I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that
names starting with underscores are reserved for the implementation. I
decided not to because it would make me look like somebody who just wastes
other people's time instead of finding real bugs.
Come on, how serious should we take this rule? This wont ever be an issue

I think you all misunderstood me. I know this rule, so its pretty easy to
avoid using them myself.
The question was more is it worth going on a holy crusade and make me look
like a fool who worries too much about C instead of writing software. I did
ask a few coworkers and funnily they all said no I wouldnt tell :)


Let's consider another rule you probably know: Once
you've freed a piece of dynamic memory, it's no longer
yours and you mustn't try to use it. Sound familiar?

All right, then: What would you say if one of your
colleagues wrote a function like this

struct node { struct node *next; ... };
...
void free_linked_list(struct node *head) {
for ( ; head != NULL; head = head->next)
free (head);
}

Even though it's completely illegal, it will "work" on
many systems. If it "works" on all the systems you
happen to be using at the moment, it's not a "real bug,"
right? Would you ask your colleague to change it anyhow?

--
Er*********@sun.com

Mar 2 '06 #18
"ok" <la@hm.com> writes:
"ok" <la@hm.com> wrote in message
news:du**********@news2.zwoll1.ov.home.nl...
I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that
names starting with underscores are reserved for the implementation. I
decided not to because it would make me look like somebody who just wastes
other people's time instead of finding real bugs.
Come on, how serious should we take this rule? This wont ever be an issue


I think you all misunderstood me. I know this rule, so its pretty easy to
avoid using them myself.
The question was more is it worth going on a holy crusade and make me look
like a fool who worries too much about C instead of writing software. I did
ask a few coworkers and funnily they all said no I wouldnt tell :)


Going on a "holy crusade" over this would undoubtedly make you look
like a fool. But I thought you were asking whether you should mention
it to the author of the code. I see no reason not to do so.

You're perfectly willing to engage in a lengthy public discussion of
this issue, as well as discussing it with your coworkers, but you're
agonizing over whether to send a brief e-mail to the author of the
code. It looks like you think there's some strong reason *not* to
inform the author, but I haven't a clue what that reason might be.
What's the problem?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 2 '06 #19
Eric Sosman wrote:
.... snip ...
Let's consider another rule you probably know: Once
you've freed a piece of dynamic memory, it's no longer
yours and you mustn't try to use it. Sound familiar?

All right, then: What would you say if one of your
colleagues wrote a function like this

struct node { struct node *next; ... };
...
void free_linked_list(struct node *head) {
for ( ; head != NULL; head = head->next)
free (head);
}

Even though it's completely illegal, it will "work" on
many systems. If it "works" on all the systems you
happen to be using at the moment, it's not a "real bug,"
right? Would you ask your colleague to change it anyhow?


This is very likely to generate a heisenbug. All is well until an
interrupt occurs between executing free and executing "head =
head->next".

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
Mar 3 '06 #20

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

Similar topics

0
by: Tom Blackwell | last post by:
Today I installed the 'mechanoid' package from sourceforge, but the self-test failed. On looking into it, I noticed odd behaviour in the handling of single underscore module names. Importing into...
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...
10
by: Axter | last post by:
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? ...
2
by: AntiPasta | last post by:
A good day to you all, I had an old code project lying around, written in C + assembly and targeted for X86 Linux, that I intended to compile on Win32 as well. I'm using GCC and NASM on Linux...
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; }
13
by: PromisedOyster | last post by:
Many in our development team have came from a C++ background and are in the practice of prefixing private class variables with an underscore to improve readability and avoid naming collisions with...
4
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4. I notice for form elements that contain spaces, PHP substitutes an underscore for the element name when the form is submitted. For example, if I have this page...
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...

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.