473,900 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

_ and __ significance

I have seen many variables or structures declared as _ or __ prefixed .
Can anyone explain the significance of _ or __ particularly . I mean ,
I wanted to know the convention for using _ and __ .

Sep 25 '06
18 11199
kondal said:

<snip>
I used the phrase 'general convention' because C language doesn't stop
me in using a underscore in variables.
It does, however, warn you off from using them at the beginning of your
identifier names. In 1977, a 19-year-old trackside fire marshal - Jansen
van Vuuren - followed the "general convention" (anyone coming? No, okay, so
it must be safe to cross, right?), and crossed Kyalami carrying a fire
extinguisher. In so doing, he invaded racing-car space. Tom Pryce's car
struck him a second or two later. Both Pryce and van Vuuren were killed.

Stay out of implementation namespace.

How can you say it is reserved
namespace only for the C language standard and usable only by the C
language implementors.
4.1.2: "All external identifiers that begin with an underscore are reserved.
All other identifiers that begin with an underscore and either an
upper-case letter or another underscore are reserved."

--
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)
Sep 26 '06 #11

Richard Heathfield wrote:
kondal said:

<snip>
I used the phrase 'general convention' because C language doesn't stop
me in using a underscore in variables.

It does, however, warn you off from using them at the beginning of your
identifier names. In 1977, a 19-year-old trackside fire marshal - Jansen
van Vuuren - followed the "general convention" (anyone coming? No, okay, so
it must be safe to cross, right?), and crossed Kyalami carrying a fire
extinguisher. In so doing, he invaded racing-car space. Tom Pryce's car
struck him a second or two later. Both Pryce and van Vuuren were killed.

Stay out of implementation namespace.

How can you say it is reserved
namespace only for the C language standard and usable only by the C
language implementors.

4.1.2: "All external identifiers that begin with an underscore are reserved.
All other identifiers that begin with an underscore and either an
upper-case letter or another underscore are reserved."

--
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)
Thank you. Can you tell me which C compiler is close to C spec? I
generally use gcc and it didn't give me any warning.

-kondal

Sep 26 '06 #12
kondal said:
>
Richard Heathfield wrote:
>kondal said:
<snip>
>>
How can you say it is reserved
namespace only for the C language standard and usable only by the C
language implementors.

4.1.2: "All external identifiers that begin with an underscore are
reserved. All other identifiers that begin with an underscore and either
an upper-case letter or another underscore are reserved."

Thank you. Can you tell me which C compiler is close to C spec? I
generally use gcc and it didn't give me any warning.
C compilers are only required to give diagnostic messages for syntax errors
and constraint violations. Invading implementation namespace is neither of
those, so no message is required.

You have *had* your warning, right there in 4.1.2: "Don't. Do. This." You
shouldn't need another.

--
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)
Sep 26 '06 #13

Richard Heathfield wrote:
kondal said:

Richard Heathfield wrote:
kondal said:
<snip>
>
How can you say it is reserved
namespace only for the C language standard and usable only by the C
language implementors.

4.1.2: "All external identifiers that begin with an underscore are
reserved. All other identifiers that begin with an underscore and either
an upper-case letter or another underscore are reserved."
Thank you. Can you tell me which C compiler is close to C spec? I
generally use gcc and it didn't give me any warning.

C compilers are only required to give diagnostic messages for syntax errors
and constraint violations. Invading implementation namespace is neither of
those, so no message is required.

You have *had* your warning, right there in 4.1.2: "Don't. Do. This." You
shouldn't need another.

--
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)
OK, I understand.
It does, however, warn you off from using them at the beginning of your
identifier names.

My curiosity is to know which C compiler gives the warning. If it is
defined only in C spec and not used by the compilers then what is the
use? I do not want to initiate any argument here, it could just be that
nobody cares about it.

I've seen lot of source codes which use underscores for structure names
and variables. as I said gcc (v 3.2.2) doesn't produce any warning.

-kondal

Sep 26 '06 #14
kondal said:
>
Richard Heathfield wrote:
>It does, however, warn you off from using them at the beginning of your
identifier names.

My curiosity is to know which C compiler gives the warning.
No, the *Standard* warns you off from using leading underscores.
If it is
defined only in C spec and not used by the compilers then what is the
use?
The C compilers DO use identifiers with leading underscores, and that's why
you shouldn't.

Look, it's very simple.

You stay over here. The compiler writer stays over there. You don't get in
his way, and he won't get in yours. Easy.
I do not want to initiate any argument here, it could just be that
nobody cares about it.
Well, I care about not using identifiers that the implementation uses,
because I would like my programs to work. If you don't need your programs
to work, there is no need for you to care.
I've seen lot of source codes which use underscores for structure names
and variables. as I said gcc (v 3.2.2) doesn't produce any warning.
As I've said, it doesn't have to. You had your warning already, in the C
Standard. If you can't be bothered to pay attention to that warning, why
would you bother to pay any attention to gcc's warning, were it to give
one?

--
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)
Sep 26 '06 #15
kondal wrote:
OK, I understand.
I don't think so.
My curiosity is to know which C compiler gives the warning. If it is
defined only in C spec and not used by the compilers then what is the
use?
How would a compiler know when to give a warning? Let's say you
#include <stdio.hin your program and that header declares names such
as _iobuf, how would the compiler distinguish between code that you
wrote and code from the standard header?
I've seen lot of source codes which use underscores for structure names
and variables. as I said gcc (v 3.2.2) doesn't produce any warning.
The code of your standard library is not a good example to follow. As
mentionned before, those who write <stdio.hand other standard library
headers are allowed to use names that begin with underscores. You are
not allowed to use those same names. In this way, you don't conflict
with them.

Regards,
Bart.

Sep 26 '06 #16
Richard Heathfield wrote:
kondal said:
>Richard Heathfield wrote:
[...]
>I've seen lot of source codes which use underscores for structure names
and variables. as I said gcc (v 3.2.2) doesn't produce any warning.

As I've said, it doesn't have to. You had your warning already, in the C
Standard. If you can't be bothered to pay attention to that warning, why
would you bother to pay any attention to gcc's warning, were it to give
one?
Well, not everyone has committed every paragraph of the Standard to
memory (or can tease out the meaning in all the paragraphs if they had!)
In this case one would not know they have violated the Standard, even
if they were the type of person who might otherwise pay attention to a
diagnostic.

It does not follow that accidental ignorance of some paragraphs
indicates that the coder is more likely to ignore an honest-to-gods
diagnostic.

Simply put, even coders familiar with a good chunk of the Standard may
just know that an underscore is a valid identifier character and that
they've seen the identifier used in some specific cases. This might
lead to the incorrect assumption that this is merely a naming convention
(much like commenting styles, or brace placement, or Hungarian notation).

Perhaps I'm admitting to some terrible sin, but I will never commit the
entire Standard to memory, and know that even if I did I might come up
with some creative misunderstandin gs on implementation.

So, it follows that I will continue to discover new aspects of the
language and correct incorrect assumptions over time. Since I sometimes
try to participate in Real Life, and only partly spend my time with C,
this is a reasonable limitation I've learned to accept!

This does not mean that I would necessarily ignore a diagnostic.
Sep 26 '06 #17
Clever Monkey said:

<snip>
>
So, it follows that I will continue to discover new aspects of the
language and correct incorrect assumptions over time. Since I sometimes
try to participate in Real Life, and only partly spend my time with C,
There's your problem right there! ;-)

--
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)
Sep 26 '06 #18
On 25 Sep 2006 23:50:39 -0700, in comp.lang.c , "kondal"
<ko******@gmail .comwrote:
>It does, however, warn you off from using them at the beginning of your
identifier names.

My curiosity is to know which C compiler gives the warning.
None, to my knowledge.
>If it is
defined only in C spec and not used by the compilers then what is the
use?
Compiler and C standard library writers can use it in their code.
>I've seen lot of source codes which use underscores for structure names
and variables. as I said gcc (v 3.2.2) doesn't produce any warning.
Its not required to.
--
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
Sep 27 '06 #19

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

Similar topics

3
1915
by: Anonymous | last post by:
In PHP Whats the difference between $yourname = @$_POST; AND $yourname = $_POST; In particular, what is the significance of '@' as a prefix to the variable? Thanks in advance
4
2595
by: Prem Mallappa | last post by:
Hello can anybody please tell me what is the significance of 0; 1; or something like 100;
2
2602
by: Prem Mallappa | last post by:
what is the significance of 0; 1; or 100;
5
2844
by: kernel.lover | last post by:
hello, I want to know if a fuction say malloc is declared as void *malloc() then whats the significance of void here. Does void * is used when function has the flexibility to return any type of value by casting that functions with appropriate data type?
4
1271
by: Frank Rizzo | last post by:
In some examples with inheriting, I see the overloaded function always call its base. For instance, in this case where the ListView control is being extended. public class ListViewEx : System.Windows.Forms.ListView { protected override void OnColumnClick(ColumnClickEventArgs e) { ...various code to extend the control
2
1504
by: | last post by:
What is the significance in using MVC architechture in Dotnet? I think the framework itself is based on MVC The view being the Asp.Net The Controller being the code-behind file .... Is that so?
26
1551
by: joe | last post by:
My experiments show that the random number generator in Microsoft's VC++6 compiler is a statistical RNG with a significance level 1.0%. Statistical testing at SL >1.0% (for example 1.001%) passes the test, but 1.0% does not pass... Can anybody confirm this finding? The RNG function of the various SW products can be analyzed and classified better using its significance level
0
9997
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9845
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11276
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8043
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7204
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6082
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.