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
19 18098
On 16 Aug 2005 20:09:54 -0700, "Robert Gamble" <rg*******@gmai l.com>
wrote in comp.lang.c: 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.
Your statement is too broad.
Every identifier starting with an underscore in the following snippet
is valid in the application's namespace in the context where it is
declared:
#include <stdio.h>
int main(void)
{
int _123 = 0;
int _abc;
double _;
typedef struct _xyz
{
int _456;
int _all;
} _qrs;
_qrs _def = { 3, 4 };
_abc = _def._456;
_abc *= _def._all;
_ = _abc / 2.0;
printf("%f\n", _);
return _123;
}
And it must produce the output "6.000000" on any conforming C
implementation.
Here is the actual text of the standard for the two cases where the
underscore makes identifiers reserved:
"— 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."
Note that leading underscores are specifically not reserved at block
scope as long as they are not followed by a second underscore or an
upper case letter.
--
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
On Wed, 17 Aug 2005 13:15:21 +0900, "Roman Mashak" <mr*@tusur.ru >
wrote in comp.lang.c: 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.
Actually, this one is wrong, my mistake in quoting from memory instead
of looking it up in the standard. All identifiers beginning with an
'_' are reserved at file scope, so "_0" through "_9" and just plain
"_" are reserved outside of a block.
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.
When is says "reserved for the implementation" it means exactly that,
and your applications and libraries are not part of the
implementation.
Third parties who develop libraries for distribution certainly don't
want their users complaining that including one of their header files
or linking to one of their libraries causes the compile or link to
break, or even worse, the program builds but suddenly has "strange"
errors. Such libraries are often written by the compiler implementer,
in which case they have a perfect right to use those symbols, or for a
particular compiler and the vendor has tested it to make sure there
are no conflicts.
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
If you do you violate the implementation name space, the C standard
doesn't define what will happen. Most likely any such identifier that
you use won't match one used by your implementation and the program
will work just fine. If the name does clash, you may get the compiler
or linker errors I mentioned above, or the strange problems.
Here are three lines from the stdio.h standard header supplied with
Microsoft Visual C++ 6.0:
#ifndef _INC_STDIO
#define _INC_STDIO
....and:
#endif /* _INC_STDIO */
So what do you think will happen if I use that implementation on this
source file:
#include <stdio.h>
int main(void)
{
int _INC_STDIO = 0;
return _INC_STDIO;
}
???
Replace the string "_INC_STDIO " with nothing, and see what the
compiler has to work with after the preprocessor phase.
The point is, while there are a few cases where you can use a leading
underscore, it's not worth remembering the rules. Just never define
any identifier, including macros, in your programs that begin with an
underscore and you'll never have that particular problem. There is
absolutely no compelling need or any possible gain to doing so.
--
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
Roman Mashak wrote on 17/08/05 : 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.
It has no peculiar meaning, but it belongs to the implementation
namespace. Users should not have names starting with with _[_A-Z]
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html
"C is a sharp tool"
On 16 Aug 2005 20:09:54 -0700, in comp.lang.c , "Robert Gamble"
<rg*******@gmai l.com> wrote: Identifiers starting with an underscore are reserved, there is no such restriction on identifiers containing consecutive underscores.
Yes there is:
All identifiers that begin with an underscore and either an
uppercase letter or another underscore are always reserved for any
use
..
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-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 =----
Mark McIntyre wrote: On 16 Aug 2005 20:09:54 -0700, in comp.lang.c , "Robert Gamble" <rg*******@gmai l.com> wrote:
Identifiers starting with an underscore are reserved, there is no such restriction on identifiers containing consecutive underscores.
Yes there is: All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use
See my response to Daniele.
Robert Gamble
Mark McIntyre <ma**********@s pamcop.net> writes: On 16 Aug 2005 20:09:54 -0700, in comp.lang.c , "Robert Gamble" <rg*******@gmai l.com> wrote:
Identifiers starting with an underscore are reserved, there is no such restriction on identifiers containing consecutive underscores.
Yes there is: All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use
I think the reference was to identifiers like foo__bar.
--
Keith Thompson (The_Other_Keit h) 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.
Keith Thompson wrote: Mark McIntyre <ma**********@s pamcop.net> writes: On 16 Aug 2005 20:09:54 -0700, in comp.lang.c , "Robert Gamble" <rg*******@gmai l.com> wrote:
Identifiers starting with an underscore are reserved, there is no such restriction on identifiers containing consecutive underscores.
Yes there is: All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use
I think the reference was to identifiers like foo__bar.
Exactly. I was trying to say that having consecutive underscores alone
doesn't put it into the reserved category, I thought my original
wording was pretty clear, I guess I was wrong.
Robert Gamble
On 17 Aug 2005 16:13:15 -0700, in comp.lang.c , "Robert Gamble"
<rg*******@gmai l.com> wrote: Mark McIntyre wrote: On 16 Aug 2005 20:09:54 -0700, in comp.lang.c , "Robert Gamble" <rg*******@gmai l.com> wrote:
>Identifiers starting with an underscore are reserved, there is no such >restriction on identifiers containing consecutive underscores.
Yes there is:
See my response to Daniele.
I read your original post as relating to identifiers starting with
underscores, since thats how the sentence begins. If you meant it to
relate to having two underscores elsewhere in the macro name, that
wasn't at all clear.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-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 =----
Mark McIntyre wrote: On 17 Aug 2005 16:13:15 -0700, in comp.lang.c , "Robert Gamble" <rg*******@gmai l.com> wrote:
Mark McIntyre wrote: On 16 Aug 2005 20:09:54 -0700, in comp.lang.c , "Robert Gamble" <rg*******@gmai l.com> wrote:
>Identifiers starting with an underscore are reserved, there is no such >restriction on identifiers containing consecutive underscores.
Yes there is:
See my response to Daniele.
I read your original post as relating to identifiers starting with underscores, since thats how the sentence begins. If you meant it to relate to having two underscores elsewhere in the macro name, that wasn't at all clear.
In the first part I used "starting with", in the second I used
"containing ". If I meant identifiers starting with consecutive
underscores, that is what I would have said. I assumed that one could
easily deduct that an identifier beginning with multiple underscores
would be reserved as per the first part of my statement. I don't think
the statement was really that poorly worded but I will try to be more
clear going forward.
Robert Gamble
Robert Gamble <rg*******@gmai l.com> wrote: I don't think the statement was really that poorly worded but I will try to be more clear going forward.
Had you not misused the comma, it might've been clearer, IMO. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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):
|
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)) { ... }
|
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.
|
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;
}
|
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
| |
by: Martin Jørgensen |
last post by:
Hi,
- - - - - - - - - - - - - - -
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
|
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 __ .
|
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
|
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:
...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |