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

The '_' char in variable names

Upon meandering through source code I noticed a large amount of
preprocessor constants with one or two '_' characters prefixed and
postfixed to them. For example: __SYSCORE__ or __IND86__.

What do the '__' before and after the constant supposed to denote?
Why put them there?
Nov 13 '05 #1
9 2528
On Sat, 11 Oct 2003 11:04:07 +0200, Yoni Rabkin
<yo********@member.fsf.org> wrote:
Upon meandering through source code I noticed a large amount of
preprocessor constants with one or two '_' characters prefixed and
postfixed to them. For example: __SYSCORE__ or __IND86__.

What do the '__' before and after the constant supposed to denote?
Why put them there?


Names starting with two underscores are reserved for the C compiler
builders.
You can't use a variable name in your code with two underscores and
expect it to work on all compilers.
Nov 13 '05 #2
Serve La writes:
You can't use a variable name in your code with two underscores and
expect it to work on all compilers.


I thought the rule applied to *leading* underscores??
Nov 13 '05 #3
> > You can't use a variable name in your code with two underscores and
expect it to work on all compilers.


I thought the rule applied to *leading* underscores??


within variable names you can use underscores as you want like:

my_funny_variable

but you should avoid using leading underscores like:

_iam_great

or

__iamgreater

but all in all, this is just conventio to prevent name clashes, you are not
forced to care for this recommendation.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 13 '05 #4
In article <bm************@ID-176797.news.uni-berlin.de>,
cody <do*********************@gmx.de> wrote:
but all in all, this is just conventio to prevent name clashes, you are not
forced to care for this recommendation.


Recommendation? The ANSI/ISO/IEC 9899-1999 standard is clearly
reserving (almost all) identifiers with leading underscores for use by
the implementation. This means that such identifiers shall not be
created by the programmer. You can ignore this standard, but then your
program is no longer C.

--
Göran Larsson http://www.mitt-eget.com/
Nov 13 '05 #5
On Sat, 11 Oct 2003 07:47:09 -0700, "osmium" <r1********@comcast.net>
wrote:
Serve La writes:
You can't use a variable name in your code with two underscores and
expect it to work on all compilers.


I thought the rule applied to *leading* underscores??


Yes, I see now that wasn't clear from my text.

Nov 13 '05 #6
On Sat, 11 Oct 2003 15:53:21 +0200, in comp.lang.c , "cody"
<do*********************@gmx.de> wrote:
but all in all, this is just conventio to prevent name clashes, you are not
forced to care for this recommendation.


Actually, you are. At least if you want to write legal C.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #7
those who know me have no need of my name <no****************@usa.net> writes:
[...]
if only the separation were more pervasive. as the c standard evolves it
routinely intrudes on the client's namespace, long after having made the
underscore reservation, i.e., almost all the new identifiers added by c99
should have been in the reserved space. of course reality intrudes, as you
noted -- it makes for ugly identifiers, e.g., _Creal(), _Cimag() and
_Cproj() -- such ugliness makes it easy for a committee to decide on
creal(), cimag() and cproj(), even if there is a fair chance of a
collision. the rationale goes: the names chosen are what one would
naturally have called them, so the collisions would mostly be against
functions with identical intent. the down side is a c99 compiler now
*knows* what creal() is supposed to do, whether <complex.h> is included or
not, so if there is any semantic difference (between your actual function
and the code the compiler produces) it may not be exposed until the program
misfunctions and that is detected.


If only namespaces had been implemented as true namespaces, not as
ugly little spelling conventions. Assuming C++-style syntax,
everything in the standard library could have been C::foo (for various
values of foo). Each implementer could have its own top-level
namespace: gcc::, posix::, etc. Individual programmers could use
whatever identifiers they want, as long as they don't conflict with
keywords (introducing new keywords would still be a problem).

--
Keith Thompson (The_Other_Keith) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #8
In article <lz************@cts.com>, Keith Thompson <ks*@cts.com> wrote:
If only namespaces had been implemented as true namespaces, not as
ugly little spelling conventions. Assuming C++-style syntax,
everything in the standard library could have been C::foo (for various
values of foo). Each implementer could have its own top-level
namespace: gcc::, posix::, etc. Individual programmers could use
whatever identifiers they want, as long as they don't conflict with
keywords (introducing new keywords would still be a problem).
Hmm...

--------
preprocessor::include <stdio.h>

keyword::int main(keyword::void)
{
using keyword::for;
using keyword::int;

int i;

for(i=0;i<42;i++)
{
int j;

for(j=0;j<17;j++)
{
C::printf("%d\t%d\n",i,j);
}
}

keyword::return 0;
}
--------

'Twould be ugly, and probably a nightmare to write a parser for, but I
could see it working...
dave
(who really should go get some sleep instead of posting crazy ideas
to usenet)

--
Dave Vandervies dj******@csclub.uwaterloo.ca[S]till not good enough for Richard Heathfield, but what can you do, really?

You could always write "only for clever people" on the cover.
--Ben Pfaff and Richard Heathfield in comp.lang.c
Nov 13 '05 #9
"Dave Vandervies" <dj******@csclub.uwaterloo.ca> wrote in message
news:bm**********@rumours.uwaterloo.ca...
int main(void) {
int i;

for(i=0;i<42;i++)
{
int j;

for(j=0;j<17;j++) {
C::printf("%d\t%d\n",i,j);
}
}

return 0;
}


Only using the namespace construct for variable names improves this a lot.
Using them for keywords is over the top, it's not like a new standard
introduces 50 new keywords.

<ot>
By the way, I had some problem once when porting a C++ program to a newer
version of the same compiler.
In an attempt to comply to the C++ standard they implemented digraphs.
The old code had something like this:
X<::Y> x; and this gave me a really weird error message. (Spot the digraph)
adding a space fixed it.
If this construct will ever be added to C, this could be a problem.
</ot>
Nov 13 '05 #10

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

Similar topics

35
by: Ying Yang | last post by:
Hi, whats the difference between: char* a = new char; char* b = new char; char c ;
19
by: gaga | last post by:
I can't seem to get this to work: #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *names; char **np;
15
by: Gregg Woodcock | last post by:
My compiler (m68k-gcc) does not allow this (simplified example; not my real code) and I don't see why not: { char *arrayCharPtr1 = {"a", "ab", NULL}; char *arrayCharPtr2 = {"A", "AB", NULL};...
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
8
by: OziRus | last post by:
Hi, I've char* array that I defined like char *str. I want to read from a file, that contains names in each row, and assign them to my str char * array. m is a char array, f is a file...
9
by: happyvalley | last post by:
I just wonder how to pass arguments to this function with a char** void oldmain(int argv, char**argc) { ........ } void main(void) { int argv;
1
by: lumo2000 | last post by:
hello NG, i am trying to do some syscalls and therefore i need to put some text together. its no problem as long i want to cout the text to display, but when i want to use it as parameter for...
33
by: Michael B Allen | last post by:
Hello, Early on I decided that all text (what most people call "strings" ) in my code would be unsigned char *. The reasoning is that the elements of these arrays are decidedly not signed. In...
4
jlm699
by: jlm699 | last post by:
I've looked at the other articles about maps of maps and am still stuck on this! I'm trying to basically make an enumeration of a data monitoring app. Instead of displaying numbers for certain...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll 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...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.