473,796 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A question about ## vs. juxtaposition

I've been acting as messenger the past few days between the BOOST and
Digital Mars peoples, and they can't seem to come to an agreement
about the semantics of using ## vs. juxtaposition. The problem arose
when I was trying to compile a boost example program with the DM
compiler, and the name of a file which was put together by a set of
macros, ended up as,
....\...\list10 .cpp
vs.
....\...\list10 .cpp

(notice the space before the period)

The macro where the problem occurs is in a file called
"...boost\mpl\l ist.hpp", where it goes:

# define MPL_AUX_LIST_HE ADER
BOOST_PP_CAT(li st,BOOST_MPL_LI MIT_LIST_SIZE). hpp /**/

which I was able to work-around by adding the ##, such as:
......,BOOST_MP L_LIMIT_LIST_SI ZE)##.hpp /**/

I reported the problem to boost mailing list, and got this reply:
The compilers are wrong to insert a space, and a concatenation here is undefined
behavior. A better way to fix it would be to try this:

#define MPL_AUX_LIST_HE ADER \
MPL_AUX_LIST_HE ADER_I(BOOST_PP _CAT(list,BOOST _MPL_LIMIT_LIST _SIZE)) \
/**/
#define MPL_AUX_LIST_HE ADER_I(name) name.
After posting the above at the DM forum, I got this reply:
I don't see how that derives from the spec. The only token concatention
allowed by the spec is with ##, extra whitespace should be quite irrelevant.
## is defined as token concatenation, so I don't see how that is undefined.
I suggested a compromise: just get rid of the space, and let a popular
bug live, if that's what it is, but DM insist:
The separator inserted by dmc is to make the preprocessor work right, it
isn't easilly removed. I don't really understand why boost seems to want to
rely on the 'juxtaposition-equals-concatenation' kludge, the ## operator was
added to Standard C specifically to move away from that practice.


Would someone here be so kind to clarify this question for me, and
better yet, if possible, settle it by pasting the section of the
Standard that pertains.

Thanks in advance.
dan

Jul 22 '05 #1
1 1784
Sorry, I made an error when copying and pasting to my original post.
The last line of the first quoted block, where it says,
#define MPL_AUX_LIST_HE ADER_I(name) name.
should actually have said
#define MPL_AUX_LIST_HE ADER_I(name) name.hpp

Anyhow, I got a more detailed reply from the person from boost that
answered the first time, I'll just paste it below. It seems pretty
comprehensive to me, but then again, who am I? I'd welcome any
further observations.
---------------------------------------------------- Even if 'concatenation' per-se is not called for, and against
the Standard, could it be that the "." (dot) relieves the
preprocessor from
responsibility for
adding a space at the end of the preceding string (since the
dot already
acts as
a kind of 'separator'..)?
No. The preprocessor does not "insert spaces" *ever*. At this point
in translation, the preprocessor is operating on preprocessing tokens,
not characters. There is a big difference between a lack of
whitespace and concatenation. The first simply has adjacent
preprocessing tokens, while the second forms a new preprocessing
token. E.g.

#define ID(x) x

#define MACRO(a, b) ID(a)b

MACRO(+,+)

results in two immediately adjacent '+' preprocessing tokens. There
is no intervening whitespace. Whether or not whitespace exists is
irrelevant for all purposes *except* stringizing and the creation of
an <h-char-sequence>.

A preprocessor that does text stream -> text stream must insert
whitespace in order to avoid the errant retokenization that would
occur when the result gets reprocessed by some other tool (such as a C
or C++ compiler). However, that is just a hack to make it work
similarly in the presence of retokenization which does not exist in
the phases of translation.
I just find it hilarious how the boost libraries work with so
many compilers, but only need dozens of ## in many files to
work with DM. I wouldn't be surprised at all that they'd be
all wrong; --won't be the first time that everybody is wrong,
but this bug may be just about ready for acceptance by
ANSI/ISO/whatever... ;-)
I wish that arbitrary token-pasting was well-defined. However, the
example given doesn't even make sense (per se). The reason is that
token-pasting occurs prior to rescanning, so a construction like this:

#define A(x) B(x) ## .h
#define B(x) x

The period (.) gets concatenated to right parenthesis before the
expansion of B(x). Even if arbitrary token-pasting was well-defined,
the argument 'x' could contain any amount of whitespace, and cause the
construction to not work properly:

#define EMPTY()

A(file EMPTY()) // file .h

In other words, there are only certain points in which whitespace is
removed or when whitespace is condensed to only a single whitespace.
This is not one of them. As I said before, however, this kind of
problem only occurs during stringizing and during the creation of a
header-name preprocessing token of the form <h-char-sequence>.

Further, there is only one sure-fire way to guarantee that no
whitespace exists and that is to concatenate to a placemarker
preprocessing token ala C99:

#define NO_LEADING(x) NO_LEADING_I(, x)
#define NO_LEADING_I(p, x) p ## x

#define NO_TRAILING(x) NO_TRAILING_I(, x)
#define NO_TRAILING_I(p , x) x ## p

#define NO_LEADING_AND_ TRAILING(x) \
NO_LEADING(NO_T RAILING(x)) \
/**/

....but that is not currently well-defined in C++ as it is in C99.
--------------------------------------------------------------
------------------------
>The separator inserted by dmc is to make the preprocessor work right, it >isn't easilly removed. I don't really
understand why boost seems to want to >rely on the
'juxtaposition-equals-concatenation' kludge, the ## operator
was >added to Standard C specifically to move away from that
practice.


Juxtaposition is not concatenation, and a preprocessor that is
operating at the character level rather than the preprocessing token
level at this point in translation has to jump through hoops to mimic
the behavior the actual phases of translation. This is not a kludge
on Boost's side, this is a preprocessor implementation kludge
revolving around textual representation at a phase of translation
where it doesn't exist.
--------------------------------------------------------------
------------------------
Maybe if someone could paste the section of the Standard
dealing with this,
I'd much appreciate it.
Yours.
dan


There is no section of the standard that *ever* says whitespace should
be inserted. There are only places where it says whitespace should be
removed or adjacent whitespace should be condensed.

Regards,
Paul Mensonides
----------------------------------------------------

Jul 22 '05 #2

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

Similar topics

1
2859
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew story is so funny that eScrew will have to take break from time to time because eScrew needs some rest from laughing. Oh boy, here it comes... eScrew funny laugh laughing screaming crying must stop can not take any more this is killing eScrew...
220
19175
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
54
6580
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' COOL!!! ***MAN*** that would save me a buttload of work and make my life sooooo much easier!" As opposed to minor differences of this feature here, that feature there. Variations on style are of no interest to me. I'm coming at this from a...
8
2464
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew story is so funny that eScrew will have to take break from time to time because eScrew needs some rest from laughing. Oh boy, here it comes... eScrew funny laugh laughing screaming crying must stop can not take any more this is killing eScrew...
125
14860
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
5
3003
by: eScrewDotCom | last post by:
www.eScrew.com eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew story is so funny that eScrew will have to take break from time to time because eScrew needs some rest from laughing. Oh boy, here it comes... eScrew funny laugh laughing
0
2458
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew story is so funny that eScrew will have to take break from time to time because eScrew needs some rest from laughing. Oh boy, here it comes... eScrew funny laugh laughing screaming crying must stop can not take any more this is killing eScrew...
7
3157
by: Edward Yang | last post by:
A few days ago I started a thread "I think C# is forcing us to write more (redundant) code" and got many replies (more than what I had expected). But after reading all the replies I think my question about local variable initialization is still not solved. And some of the replies forked into talking about out parameters. And the thread is becoming way too deep. So I open a new thread here. My question in the previous thead has turned...
0
9679
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
9527
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
10453
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
9050
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...
0
6785
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
5441
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...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
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...

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.