Topic: Supporting string concatenation in _Pragma
Author: Myriachan <myriachan@gmail.com>
Date: Fri, 24 Jul 2015 17:55:03 -0700 (PDT)
Raw View
------=_Part_1236_191525902.1437785703985
Content-Type: multipart/alternative;
boundary="----=_Part_1237_140844367.1437785703985"
------=_Part_1237_140844367.1437785703985
Content-Type: text/plain; charset=UTF-8
It's quite annoying that the C99/C++11 directive _Pragma does not allow you
to concatenate strings. For example, with GCC/clang #pragma message:
#define ASDF "meow"
// OK
#pragma message ASDF ASDF
// Ill-formed: _Pragma takes a string literal argument
_Pragma("message \"" ASDF "\"")
From reading the Standard, I think that the reason you can't concatenate
strings in _Pragma is because string concatenation occurs at a later
phase. Despite this, it seems to me that string concatenation ought to be
allowed in a _Pragma for programmers' sake.
By the way, I feel that #pragma message ought to be standardized by C and
C++. It's really simple to define it as outputting a diagnostic with the
specified string in the matter of a failed static_assert, but without
making the program ill-formed. And it could be optional to output a
diagnostic for it; just make it accepted by all compilers.
If not #pragma message, then add something like #warning and #message, with
similar definition to #error. (The concept of "warning" is not defined by
the Standard, so #warning could also be ignored at QoI discretion like
#message / #pragma message.)
Melissa
--
---
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_1237_140844367.1437785703985
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">It's quite annoying that the C99/C++11 directive <span=
style=3D"font-family: courier new,monospace;">_Pragma</span> does not allo=
w you to concatenate strings.=C2=A0 For example, with GCC/clang <span style=
=3D"font-family: courier new,monospace;">#pragma message</span>:<br><br><di=
v class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bord=
er-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-=
wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint=
"><span style=3D"color: #800;" class=3D"styled-by-prettify">#define</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> ASDF </span><span=
style=3D"color: #080;" class=3D"styled-by-prettify">"meow"</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span=
style=3D"color: #800;" class=3D"styled-by-prettify">// OK</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #800;" class=3D"styled-by-prettify">#pragma</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> message ASDF ASDF<br></span><span s=
tyle=3D"color: #800;" class=3D"styled-by-prettify">// Ill-formed: _Pragma t=
akes a string literal argument</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>_Pragma</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #080;" class=3D"styled-b=
y-prettify">"message \""</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> ASDF </span><span style=3D"color: #080;" clas=
s=3D"styled-by-prettify">"\""</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span></div></code></div><br>From reading the=
Standard, I think that the reason you can't concatenate strings in <sp=
an style=3D"font-family: courier new,monospace;">_Pragma</span> is because =
string concatenation occurs at a later phase.=C2=A0 Despite this, it seems =
to me that string concatenation ought to be allowed in a <span style=3D"fon=
t-family: courier new,monospace;">_Pragma</span> for programmers' sake.=
<br><br>By the way, I feel that <span style=3D"font-family: courier new,mon=
ospace;">#pragma message</span> ought to be standardized by C and C++.=C2=
=A0 It's really simple to define it as outputting a diagnostic with the=
specified string in the matter of a failed <span style=3D"font-family: cou=
rier new,monospace;">static_assert</span>, but without making the program i=
ll-formed.=C2=A0 And it could be optional to output a diagnostic for it; ju=
st make it accepted by all compilers.<br><br>If not <span style=3D"font-fam=
ily: courier new,monospace;">#pragma message</span>, then add something lik=
e <span style=3D"font-family: courier new,monospace;">#warning</span> and <=
span style=3D"font-family: courier new,monospace;">#message</span>, with si=
milar definition to <span style=3D"font-family: courier new,monospace;">#er=
ror</span>.=C2=A0 (The concept of "warning" is not defined by the=
Standard, so <span style=3D"font-family: courier new,monospace;">#warning<=
/span> could also be ignored at QoI discretion like <span style=3D"font-fam=
ily: courier new,monospace;">#message</span> / <span style=3D"font-family: =
courier new,monospace;">#pragma message</span>.)<br><br>Melissa<br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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_1237_140844367.1437785703985--
------=_Part_1236_191525902.1437785703985--
.
Author: David Krauss <potswa@gmail.com>
Date: Sat, 25 Jul 2015 10:15:55 +0800
Raw View
--Apple-Mail=_14854D67-2476-4E0D-A5EF-273294F1217D
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
> On 2015=E2=80=9307=E2=80=9325, at 8:55 AM, Myriachan <myriachan@gmail.com=
> wrote:
>=20
> It's quite annoying that the C99/C++11 directive _Pragma does not allow y=
ou to concatenate strings. For example, with GCC/clang #pragma message:
The typical usage is that you use a STRINGIZE macro to generate the string =
at the last minute. (If the string is not a literal, anyway.) IIRC that=E2=
=80=99s what the examples in the standard do. This requires that you don=E2=
=80=99t have illegal tokens and you don=E2=80=99t care too much about white=
space formatting, but it=E2=80=99s good enough.
--=20
---=20
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 e=
mail 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-proposa=
ls/.
--Apple-Mail=_14854D67-2476-4E0D-A5EF-273294F1217D
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9307=
=E2=80=9325, at 8:55 AM, Myriachan <<a href=3D"mailto:myriachan@gmail.co=
m" class=3D"">myriachan@gmail.com</a>> wrote:</div><br class=3D"Apple-in=
terchange-newline"><div class=3D""><div dir=3D"ltr" class=3D"">It's quite a=
nnoying that the C99/C++11 directive <span style=3D"font-family: courier ne=
w,monospace;" class=3D"">_Pragma</span> does not allow you to concatenate s=
trings. For example, with GCC/clang <span style=3D"font-family: couri=
er new,monospace;" class=3D"">#pragma message</span>:<br class=3D""></div><=
/div></blockquote><div><br class=3D""></div><div>The typical usage is that =
you use a <font face=3D"Courier" class=3D"">STRINGIZE</font> macro to gener=
ate the string at the last minute. (If the string is not a literal, anyway.=
) IIRC that=E2=80=99s what the examples in the standard do. This requires t=
hat you don=E2=80=99t have illegal tokens and you don=E2=80=99t care too mu=
ch about whitespace formatting, but it=E2=80=99s good enough.</div></div><b=
r class=3D""></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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 />
--Apple-Mail=_14854D67-2476-4E0D-A5EF-273294F1217D--
.