220 8738 <33e7f669-7720-45ff-8f0e-66e3a4c4d12c@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Andrew Tomazos <andrewtomazos@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: "Raw" preprocessor macro arguments
Date: Mon, 20 Jan 2014 04:51:09 -0800 (PST)
Lines: 177
Approved: news@gmane.org
Message-ID: <33e7f669-7720-45ff-8f0e-66e3a4c4d12c@isocpp.org>
References: <c0398870-b265-4d02-a814-ad84a472520c@isocpp.org>
 <3fc9f495-0bb2-4432-bb79-385fe222feab@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_318_20904850.1390222269341"
X-Trace: ger.gmane.org 1390222264 26372 80.91.229.3 (20 Jan 2014 12:51:04 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 20 Jan 2014 12:51:04 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBD5KHQXXWYPRBPNX6SLAKGQELUJCHRQ@isocpp.org Mon Jan 20 13:51:12 2014
Return-path: <std-proposals+bncBD5KHQXXWYPRBPNX6SLAKGQELUJCHRQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-gg0-f197.google.com ([209.85.161.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD5KHQXXWYPRBPNX6SLAKGQELUJCHRQ@isocpp.org>)
	id 1W5EJr-0007KJ-2j
	for gclcip-std-proposals@m.gmane.org; Mon, 20 Jan 2014 13:51:11 +0100
Original-Received: by mail-gg0-f197.google.com with SMTP id q3sf11054721gge.4
        for <gclcip-std-proposals@m.gmane.org>; Mon, 20 Jan 2014 04:51:10 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=h1pnPgIUrGzgPvbVUVnNbuYN9/iY2kcOz4kSW28o5tc=;
        b=khdVDJv9bW2DiZChlsPM70/pBjOyJ8k8oK82y5QQ689XSB3bS2T+BHdw96cPpbJRAl
         XB9B7am0Zvv8uIXDHDWJ25SB0VaB3l/U/2Ph548bcN+LtKr3tWIAypqus0SQSYgxADTB
         1AArzN6znqTwlnMzuSP8gIOAMwuRAVWMM2SGuSY7e1reghcnRjEXvmJn9C64eeB8cI+y
         V0l6hXssvo8zGvATo85MSxsypI8qptd8mt9syV0hNFW+dKqnez+8oNWEkxhJg2pugLN8
         ckbawlHRMyNtx9hkwcVy5Y69zOS0arcPjJAaTGggyr9tDGNiVA12pV0WZaUjHrvLS1tx
         x8ow==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=h1pnPgIUrGzgPvbVUVnNbuYN9/iY2kcOz4kSW28o5tc=;
        b=Gx44w0xs9msWVLB9cpPUBLrMFeAaB2F0l5NjupXk2VgQI1c/x+gm8O+eyPFflcU/zG
         nFRshq/btI/hb3uFh7WbnqeSk9pKV3S///efJeAg6TC4qAB49r0mHoGNrgWe8ItZ2u85
         HjHOPIZbt0Fbp8ulCdDPTZETpNcBDCNQHNz0fOBj6HU7ZnN1/fNjFvXKxBpDVJ5xT0d9
         Tq2ViVEDnaz89W0+rii365usVpRRbC7Fb+cjouLq+ds0r65ibNmVD0kUlGMQmMjxyhOw
         V4ZJp2Kz+csLbWZIcogD0u1sfNvzbJ4xbhz6p8SQmVA+o+x6qnAJcBmAM3x3PDPX88lw
         s/2g==
X-Gm-Message-State: ALoCoQk3+a64zrvA5c7/1wvXOpO+9m+hMr7OriYa5TUnVsZLcUqqsr/InB6btgUwfmlxWs9lioX8
X-Received: by 10.224.163.71 with SMTP id z7mr6400012qax.5.1390222270222;
        Mon, 20 Jan 2014 04:51:10 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.47.9 with SMTP id l9ls1017445qga.13.gmail; Mon, 20 Jan
 2014 04:51:09 -0800 (PST)
X-Received: by 10.140.105.181 with SMTP id c50mr48786qgf.12.1390222269795;
        Mon, 20 Jan 2014 04:51:09 -0800 (PST)
In-Reply-To: <3fc9f495-0bb2-4432-bb79-385fe222feab@isocpp.org>
X-Original-Sender: andrewtomazos@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:8738
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8738>

------=_Part_318_20904850.1390222269341
Content-Type: text/plain; charset=UTF-8

On Monday, January 20, 2014 9:53:04 AM UTC+1, Vittorio Romeo wrote:
>
> I would expect the program to print "1, 2, 3" or "1,2,3" - instead, it 
> fails to compile.


In the following...

#define RAW(...) __VA_ARGS__
#define STRINGIFY(mArg) #mArg
#define MAKE_STRING(mArg) std::string(STRINGIFY(mArg))

An expansion of:

MAKE_STRING(RAW(1, 2, 3))

proceeds as follows:

1. First the mArg param to MAKE_STRING is identified. mArg=`RAW(1,2,3)`
2. Then mArg is macro expanded to mArg=`1,2,3`
3. Then mArg is substituted in the MAKE_STRING replacement list producing 
`std::string(STRINGIFY(1,2,3))`
4. The MAKE_STRING invocation is now complete, and preprocessing restarts.
5. The `STRINGIFY(1,2,3)` invocation is identified, but it has 3 arguments 
and expects 1.  Error, stop.

There are several ways to fix this, but you will start heading into the 
nesting rules and other things of which there is implementation variance.

My advice would be to study Clause 16 in the standard and then study 
the implementation of the Boost.Preprocessor library if you are interested 
in going deeper into "macro metaprogramming".  You should do this before 
even considering writing a proposal regarding the preprocessor.


On Monday, January 20, 2014 9:53:04 AM UTC+1, Vittorio Romeo wrote:
>
> http://ideone.com/B5hVDS
>
> This example shows un-intuitive behavior.
> The "raw argument" is actually passed as multiple arguments, and does not 
> expand correctly.
>
> I would expect the program to print "1, 2, 3" or "1,2,3" - instead, it 
> fails to compile.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_318_20904850.1390222269341
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><font face=3D"arial, sans-serif" color=3D"#000000">On=
 Monday, January 20, 2014 9:53:04 AM UTC+1, Vittorio Romeo wrote:</font><bl=
ockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; border-l=
eft-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: s=
olid; padding-left: 1ex;"></blockquote></div><blockquote class=3D"gmail_quo=
te" style=3D"margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left=
-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><=
span style=3D"color: rgb(0, 0, 0); font-family: arial, sans-serif;">I would=
 expect the program to print "1, 2, 3" or "1,2,3" - instead, it fails to co=
mpile.</span></blockquote><div><span style=3D"font-size: 12px; line-height:=
 13px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: arial, sans=
-serif;"><br></span></div><div><span style=3D"font-size: 12px; line-height:=
 13px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: arial, sans=
-serif;">In the following...</span></div><div><span style=3D"color: rgb(0, =
0, 0); font-family: arial, sans-serif; line-height: 13px; background-color:=
 rgb(248, 248, 248); font-size: 12px; white-space: pre-wrap;"><br></span></=
div><div><span style=3D"color: rgb(0, 0, 0); font-family: arial, sans-serif=
; line-height: 13px; background-color: rgb(248, 248, 248); font-size: 12px;=
 white-space: pre-wrap;">#define RAW(...) __VA_ARGS__</span></div><div><spa=
n style=3D"color: rgb(0, 0, 0); font-family: arial, sans-serif; line-height=
: 13px; background-color: rgb(248, 248, 248); font-size: 12px; white-space:=
 pre-wrap;">#define STRINGIFY(mArg) #mArg</span></div><div><span style=3D"c=
olor: rgb(0, 0, 0); font-family: arial, sans-serif; line-height: 13px; back=
ground-color: rgb(248, 248, 248); font-size: 12px; white-space: pre-wrap;">=
#define MAKE_STRING(mArg) std::string(STRINGIFY(mArg))</span></div><div><fo=
nt face=3D"arial, sans-serif" color=3D"#000000"><br></font></div><div><font=
 face=3D"arial, sans-serif" color=3D"#000000">An expansion of:</font></div>=
<div><font face=3D"arial, sans-serif" color=3D"#000000"><br></font></div><d=
iv><font face=3D"arial, sans-serif" color=3D"#000000"><span style=3D"font-s=
ize: 12px; line-height: 20px; white-space: pre-wrap; background-color: rgb(=
248, 248, 248);">MAKE_STRING</span><span class=3D"br0" style=3D"font-size: =
12px; white-space: pre-wrap; background-color: rgb(248, 248, 248); line-hei=
ght: 13px !important;">(</span><span style=3D"font-size: 12px; line-height:=
 20px; white-space: pre-wrap; background-color: rgb(248, 248, 248);">RAW</s=
pan><span class=3D"br0" style=3D"font-size: 12px; white-space: pre-wrap; ba=
ckground-color: rgb(248, 248, 248); line-height: 13px !important;">(</span>=
<span class=3D"nu0" style=3D"font-size: 12px; white-space: pre-wrap; backgr=
ound-color: rgb(248, 248, 248); line-height: 13px !important;">1</span><spa=
n style=3D"font-size: 12px; line-height: 20px; white-space: pre-wrap; backg=
round-color: rgb(248, 248, 248);">, </span><span class=3D"nu0" style=3D"fon=
t-size: 12px; white-space: pre-wrap; background-color: rgb(248, 248, 248); =
line-height: 13px !important;">2</span><span style=3D"font-size: 12px; line=
-height: 20px; white-space: pre-wrap; background-color: rgb(248, 248, 248);=
">, </span><span class=3D"nu0" style=3D"font-size: 12px; white-space: pre-w=
rap; background-color: rgb(248, 248, 248); line-height: 13px !important;">3=
</span><span class=3D"br0" style=3D"font-size: 12px; white-space: pre-wrap;=
 background-color: rgb(248, 248, 248); line-height: 13px !important;">)</sp=
an><span class=3D"br0" style=3D"font-size: 12px; white-space: pre-wrap; bac=
kground-color: rgb(248, 248, 248); line-height: 13px !important;">)</span><=
br></font></div><div><span class=3D"br0" style=3D"font-size: 12px; white-sp=
ace: pre-wrap; background-color: rgb(248, 248, 248); line-height: 13px !imp=
ortant;"><font face=3D"arial, sans-serif" color=3D"#000000"><br></font></sp=
an></div><div><font color=3D"#000000" face=3D"arial, sans-serif"><span styl=
e=3D"font-size: 12px; line-height: 13px; white-space: pre-wrap; background-=
color: rgb(248, 248, 248);">proceeds as follows:</span></font></div><div><s=
pan class=3D"br0" style=3D"font-size: 12px; white-space: pre-wrap; backgrou=
nd-color: rgb(248, 248, 248); line-height: 13px !important;"><font face=3D"=
arial, sans-serif" color=3D"#000000"><br></font></span></div><div><span cla=
ss=3D"br0" style=3D"font-size: 12px; white-space: pre-wrap; background-colo=
r: rgb(248, 248, 248); line-height: 13px !important;"><font face=3D"arial, =
sans-serif" color=3D"#000000">1. First the mArg param to MAKE_STRING is ide=
ntified. mArg=3D`RAW(1,2,3)`</font></span></div><div><span class=3D"br0" st=
yle=3D"font-size: 12px; white-space: pre-wrap; background-color: rgb(248, 2=
48, 248); line-height: 13px !important;"><font face=3D"arial, sans-serif" c=
olor=3D"#000000">2. Then mArg is macro expanded to mArg=3D`1,2,3`</font></s=
pan></div><div><font face=3D"arial, sans-serif" color=3D"#000000">3. Then m=
Arg is substituted in the MAKE_STRING replacement list producing `std::stri=
ng(STRINGIFY(1,2,3))`</font></div><div><font face=3D"arial, sans-serif" col=
or=3D"#000000">4. The MAKE_STRING invocation is now complete, and preproces=
sing restarts.</font></div><div><font face=3D"arial, sans-serif" color=3D"#=
000000">5. The `STRINGIFY(1,2,3)` invocation is identified, but it has 3 ar=
guments and expects 1. &nbsp;Error, stop.</font></div><div><font face=3D"ar=
ial, sans-serif" color=3D"#000000"><br></font></div><div><font color=3D"#00=
0000" face=3D"arial, sans-serif">There are several ways to fix this, but yo=
u will start heading into the nesting rules and other things of which there=
 is implementation variance.</font></div><div><font color=3D"#000000" face=
=3D"arial, sans-serif"><br></font></div><div><font color=3D"#000000" face=
=3D"arial, sans-serif">My advice would be to study Clause 16 in the standar=
d and then study the&nbsp;implementation of the&nbsp;Boost.Preprocessor lib=
rary if you are interested in going deeper into "macro metaprogramming". &n=
bsp;You should do this before even considering writing a proposal regarding=
 the preprocessor.</font></div><div><br></div><font face=3D"arial, sans-ser=
if" color=3D"#000000"><br>On Monday, January 20, 2014 9:53:04 AM UTC+1, Vit=
torio Romeo wrote:</font><blockquote class=3D"gmail_quote" style=3D"margin:=
 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div =
dir=3D"ltr"><font face=3D"arial, sans-serif" color=3D"#000000"><a href=3D"h=
ttp://ideone.com/B5hVDS" target=3D"_blank" onmousedown=3D"this.href=3D'http=
://www.google.com/url?q\75http%3A%2F%2Fideone.com%2FB5hVDS\46sa\75D\46sntz\=
0751\46usg\75AFQjCNFN00duigtqjYQCPYDVTUIs2QmR1w';return true;" onclick=3D"t=
his.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fideone.com%2FB5hVDS\=
46sa\75D\46sntz\0751\46usg\75AFQjCNFN00duigtqjYQCPYDVTUIs2QmR1w';return tru=
e;">http://ideone.com/B5hVDS</a><br><br>This example shows un-intuitive beh=
avior.</font><div><font face=3D"arial, sans-serif" color=3D"#000000">The "r=
aw argument" is actually passed as multiple arguments, and does not expand =
correctly.</font></div><div><font face=3D"arial, sans-serif" color=3D"#0000=
00"><br></font></div><div><font face=3D"arial, sans-serif" color=3D"#000000=
">I would expect the program to print "1, 2, 3" or "1,2,3" - instead, it fa=
ils to compile.</font></div></div></blockquote></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_318_20904850.1390222269341--

.
