473,766 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using '__' in names

Hello, All!

I often meet that '_' or '__' is used as prefix to
functions/macros/variables names. I wonder does it have some strict meaning?
I didn't find any distinct explanation in C standard or local FAQ.

With best regards, Roman Mashak. E-mail: mr*@tusur.ru
Nov 15 '05 #1
19 18095
Roman Mashak wrote:
I often meet that '_' or '__' is used as prefix to
functions/macros/variables names. I wonder does it have some strict meaning?


If I remember: all symbols that starts with an underscore or contains
two consecutive underscores are reserved. This means that no portable
programs can uses this sort of identifiers.

Daniele
Nov 15 '05 #2
Roman Mashak wrote:
Hello, All!

I often meet that '_' or '__' is used as prefix to
functions/macros/variables names. I wonder does it have some strict meaning?
I didn't find any distinct explanation in C standard or local FAQ.

With best regards, Roman Mashak. E-mail: mr*@tusur.ru

In general, such names are reserved for the implementation. Do *not* use
names like this in code you write.[1]

HTH,
--ag

[1] There are situations where it's legal, but it's still a Bad Idea.

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com (new post 8/5)
http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
Nov 15 '05 #3
Daniele Benegiamo wrote:
Roman Mashak wrote:
I often meet that '_' or '__' is used as prefix to
functions/macros/variables names. I wonder does it have some strict meaning?


If I remember: all symbols that starts with an underscore or contains
two consecutive underscores are reserved. This means that no portable
programs can uses this sort of identifiers.


Identifiers starting with an underscore are reserved, there is no such
restriction on identifiers containing consecutive underscores.

Robert Gamble

Nov 15 '05 #4
On Wed, 17 Aug 2005 11:38:51 +0900, "Roman Mashak" <mr*@tusur.ru >
wrote in comp.lang.c:
Hello, All!

I often meet that '_' or '__' is used as prefix to
functions/macros/variables names. I wonder does it have some strict meaning?
I didn't find any distinct explanation in C standard or local FAQ.


All symbols beginning with two underscores ("__") or one underscore
followed by a upper case letter ("_A" through "_Z"), are reserved for
the implementation (compiler, its headers and library) in all
contexts.

All symbols beginning with an underscore followed by a lower case
letter ("_a" through "_z") are also reserved for the implementation at
file scope.

If you look at a header supplied by your compiler, you might see that
it includes something like this at the top:

#ifndef __STDIO_H__
#define __STDIO_H__

/* contents of header */

#endif

The point is that the standard reserves some identifiers for the
implementation so that it can define its own macros, data types,
internal helper functions, and non-standard extensions that will not
clash with any identifiers a programmer uses, if the programmer
understands and follows the rules.

Unfortunately, the vast majority of C (and C++) programmers do not
understand the rules. Most of them still define include guard macros
in their header files like this:

my_header.h:
#ifndef __MY_HEADER_H__
#define __MY_HEADER_H__
/* ... */
#endif

Because they see it in compiler supplied headers and somehow think it
is the thing to use in headers.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 15 '05 #5
On Wed, 17 Aug 2005 04:49:31 +0200, Daniele Benegiamo
<no****@nospam. com> wrote in comp.lang.c:
Roman Mashak wrote:
I often meet that '_' or '__' is used as prefix to
functions/macros/variables names. I wonder does it have some strict meaning?


If I remember: all symbols that starts with an underscore or contains
two consecutive underscores are reserved. This means that no portable
programs can uses this sort of identifiers.

Daniele


That's a mix of incorrect C and incorrect C++.

See my reply to the OP for the actual C reservations. The double
underscore "__" is free for any use in C if they are not the first two
characters.

While it is off-topic here, C++ reserves symbols with "__" anywhere in
them, but that's a language of a different color.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 15 '05 #6
Robert Gamble wrote:
Daniele Benegiamo wrote:
Identifiers starting with an underscore are reserved, there is no such
restriction on identifiers containing consecutive underscores.


ANSI have reserved them for compiler writers:

http://msdn.microsoft.com/library/de...tm/eleme_5.asp
http://msdn.microsoft.com/library/de...tm/eleme_6.asp
Not related to underscores, but maybe useful to Roman and others,
general identifier names have other restrictions (extracted from
http://www.informit.com/guides/conte...Num=185&rl=1):

The reserved standard C function names are:
* "is" followed by a lowercase letter, e.g. "isspace"
* "mem" followed by a lowercase letter, e.g. "memset"
* "str" followed by a lowercase letter, e.g. "strcmp"
* "to" followed by a lowercase letter, e.g. "tolower"
* "wcs" followed by a lowercase letter, e.g. "wcstof"

The following macros are reserved:
* Identifiers that start with E followed by a digit or an uppercase letter
* Identifiers that start with LC_ followed by an uppercase letter
* Identifiers that start with SIG or SIG_ followed by an uppercase letter
Daniele
Nov 15 '05 #7

Daniele Benegiamo wrote:
Robert Gamble wrote:
Daniele Benegiamo wrote:
Identifiers starting with an underscore are reserved, there is no such
restriction on identifiers containing consecutive underscores.


ANSI have reserved them for compiler writers:


Identifiers starting with an underscore are reserved. If an identifier
contains consecutive underscores, that does not in and of itself make
it reserved. If it starts with two consecutive underscores then it
obviously starts with one underscore which is covered in the first part
of my statement. Read carefully.

Robert Gamble

Nov 15 '05 #8
"Robert Gamble" <rg*******@gmai l.com> writes:
Daniele Benegiamo wrote:
Robert Gamble wrote:
> Daniele Benegiamo wrote:
> Identifiers starting with an underscore are reserved, there is no such
> restriction on identifiers containing consecutive underscores.


ANSI have reserved them for compiler writers:


Identifiers starting with an underscore are reserved. If an identifier
contains consecutive underscores, that does not in and of itself make
it reserved.


I think there's some confusion with C++ here, which, unlike C,
does indeed reserve all identifiers that contain consecutive
underscores. From C++98:

$ 17.4.3.1.2 Global names [lib.global.name s]
$
$ 1 Certain sets of names and function signatures are always
$ reserved to the implementation:
$
$ - Each name that contains a double underscore (__) or begins
$ with an underscore followed by an upper-case letter (2.11)
$ is reserved to the implementation for any use.

--
"Large amounts of money tend to quench any scruples I might be having."
-- Stephan Wilms
Nov 15 '05 #9
Hello, Jack!
You wrote on Tue, 16 Aug 2005 22:19:54 -0500:

JK> All symbols beginning with an underscore followed by a lower case
JK> letter ("_a" through "_z") are also reserved for the implementation at
JK> file scope.
If I unerstand you right, standard also doesn't recommend these type of
symbols in your own libraries, application etc.? Also I met this in many
SDK, developed by many respected companies.
JK> If you look at a header supplied by your compiler, you might see that
JK> it includes something like this at the top:

With best regards, Roman Mashak. E-mail: mr*@tusur.ru
Nov 15 '05 #10

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

Similar topics

11
1908
by: Qiangning Hong | last post by:
A class Collector, it spawns several threads to read from serial port. Collector.get_data() will get all the data they have read since last call. Who can tell me whether my implementation correct? class Collector(object): def __init__(self): self.data = spawn_work_bees(callback=self.on_received) def on_received(self, a_piece_of_data):
0
365
by: Matt Kunze | last post by:
Sorry to post to this again, but I sent this to the interop newsgroup and haven't received any responses and it looks like this group gets a little more traffic. I have an application written in Visual C++ and am trying to load some code written in C# as a COM object. The C++ code looks like: CComPtr<IModuleHandler> handler; HRESULT hr = handler.CoCreateInstance(CLSID_ModuleHandler); if(SUCCEEDED(hr)) { ... }
6
2901
by: jose luis fernandez diaz | last post by:
Hi, I have a C program running in background in UNIX. From a shell script I want to notify it some events. The easiest way to do it is through signals, but it is not correct because signal are not a event drivent framework. Can anyone give me other straightforward solution ? Thanks, Jose Luis.
31
2910
by: anongroupaccount | last post by:
I have an ABC with a protected member that is a reference to an object of an ABC type: class ABC { public: virtual ~ABC() = 0; protected: AnotherABC& _member; }
8
2531
by: Luciano A. Ferrer | last post by:
Hi! I was following the http://www.seomoz.org/articles/301-redirects.php article, trying to do that with one of my test sites I added this to the .htaccess file: RewriteEngine On RewriteCond %{HTTP_HOST} !^domain\.com.ar RewriteRule ^/(.*) http://domain.com.ar/$1
11
8795
by: Martin Jørgensen | last post by:
Hi, - - - - - - - - - - - - - - - #include <iostream> #include <string> #include <map> using namespace std; int main() {
18
11187
by: g.ankush1 | last post by:
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 __ .
4
2861
by: python | last post by:
Is there an official list of all Python's __<special-methods>__? I'm learning Python and trying to get an idea of what __<special-methods>__ are available and specifically, what __<special-methods>__ are used by each native Python data type? Thanks! Malcolm
22
2814
by: phil.pellouchoud | last post by:
I did some searching online and i couldn't find anything in reference to this. I am using MinGW, gcc 4.3 and am having the following compilation issue: class CFoo { public: ...
0
9568
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
9404
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
10168
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...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7381
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
6651
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
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3929
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
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.