473,749 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Are macro names subject to the double/leading underscore restrictions?

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
_INCLUDED_BLAH_ H (and I avoid them myself "just to be on the safe
side"). But if this is a mistake, then it is an astonishingly common
one. There are dozens of well-known libraries in my /usr/include that
do it.

Is this technically a mistake that doesn't matter in practice, or does
Section 17.4.3.1.2 refer only to post-processed names?

Thanks,
Pete

Dec 14 '06 #1
5 2172
Pete C wrote:
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
_INCLUDED_BLAH_ H (and I avoid them myself "just to be on the safe
side"). But if this is a mistake, then it is an astonishingly common
one. There are dozens of well-known libraries in my /usr/include that
do it.

Is this technically a mistake that doesn't matter in practice, or does
Section 17.4.3.1.2 refer only to post-processed names?

Thanks,
Pete
*ANY* identifier with a leading underscore followed by an uppercase, or
two consecutive underscores is subject to 17.4.3.1.2. Period.
Dec 14 '06 #2
Pete C wrote:
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
_INCLUDED_BLAH_ H (and I avoid them myself "just to be on the safe
side"). But if this is a mistake, then it is an astonishingly common
one. There are dozens of well-known libraries in my /usr/include that
do it.
/usr/include *is* your implementation. Since the identifiers in
question are reserved to the implementation, /usr/include is quite free
to use them.
Dec 14 '06 #3
red floyd wrote:
/usr/include *is* your implementation. Since the identifiers in
question are reserved to the implementation, /usr/include is quite free
to use them.
Hmm... I'm pretty sure that when the standard says "the
implementation" , it isn't referring to wxWidgets, boost, gtkmm or any
other crufty old library I happen to have installed in /usr/include ...
surely it is just referring to the implementation of ISO/IEC 14882 ?

Dec 14 '06 #4
Pete C wrote:
red floyd wrote:
>/usr/include *is* your implementation. Since the identifiers in
question are reserved to the implementation, /usr/include is quite free
to use them.

Hmm... I'm pretty sure that when the standard says "the
implementation" , it isn't referring to wxWidgets, boost, gtkmm or any
other crufty old library I happen to have installed in /usr/include ...
surely it is just referring to the implementation of ISO/IEC 14882 ?
That's right. Being in /usr/include is not a license to use reserved
names. That's reserved to the compiler and its associated headers.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 14 '06 #5
Pete C wrote:
I often see preple chastised for using include guards like
_INCLUDED_BLAH_ H (and I avoid them myself "just to be on the safe
side"). But if this is a mistake, then it is an astonishingly common
one. There are dozens of well-known libraries in my /usr/include that
do it.
There are thousands of people, books, magazine articles, help files, web
pages and usenet posts that uses void main, and is still incorrect
according to the standard.

There are millions of programs with bugs, but that fact will not must
encourage anything to write buggy code on purpose.

--
Salu2
Dec 14 '06 #6

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

Similar topics

10
2967
by: dan | last post by:
I have a script that selects a value in an option in a selection list according to how many letters were entered in an input box. I have it working but I am limited to what I can name the form fields because they are dynamically created by a PHP script. I can get it to work with simple name but not with names outputted by the script. Is there a change I can make to the JavaScript so I can use the dynamic names? Simple name =...
20
2831
by: Dead RAM | last post by:
Hey people, i'll try to keep this short ;) Here is what I want to type (or at least close too)... #define VER_BUILD 1 #define STR_VER_BUILD "VER_BUILD" But what happends is the preprocessor see the quots in STR_VER_BUILD and replaces that text with "VER_BUILD"... I need it to see the VER_BUILD and replace it with 1, and only after doing
3
2633
by: John | last post by:
Please, consider this macro: #define mymacro(arg1, arg2) arg1 and arg2 Then it is used: mymacro(boys, girls) How is its expansion?
10
19208
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? Is it only narrowly defined by the compiler's internal name handling? Or does it also include the library that comes with the compiler? Does it include the OS library as part of the implementation?
7
1625
by: Michael B Allen | last post by:
If I define a variadic macro like say: #define PRINT(fmt, ...) _myprintf(__FILE__ ": " fmt, __VA_ARGS__) and I call this like: PRINT("no args"); the preprocessor generates:
19
18086
by: Roman Mashak | last post by:
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: mrv@tusur.ru
28
2639
by: richardlang | last post by:
Anyone out there ever come across a preprocessor macro that compares an argument value against the predefined __DATE__ macro in order to control conditional compilation based on date. Something along the lines of... # define DateLaterThan(x) ... that could be used for things like
16
2604
by: per9000 | last post by:
Hi, I recently started working a lot more in python than I have done in the past. And I discovered something that totally removed the pretty pink clouds of beautifulness that had surrounded my previous python experiences: magic names (I felt almost as sad as when I discovered the strange pink worms that eat you in nethack, not to mention the mind flayers - I really hate them). I guess all programming languages have magic names to some...
20
4201
by: benhoyt | last post by:
Hi guys, I've been using Python for some time now, and am very impressed with its lack of red tape and its clean syntax -- both probably due to the BDFL's ability to know when to say "no". Most of the things that "got me" initially have been addressed in recent versions of Python, or are being addressed in Python 3000. But it looks like the double underscores are staying as is. This is probably a good thing unless there are better...
0
8833
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
9568
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
9389
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9335
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,...
0
9256
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
6079
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
4709
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
3320
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
2794
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.