Topic: Visual C++'s __identifier keyword
Author: Myriachan <myriachan@gmail.com>
Date: Thu, 30 Oct 2014 12:52:10 -0700 (PDT)
Raw View
------=_Part_420_1015641013.1414698730942
Content-Type: text/plain; charset=UTF-8
I think Visual Studio's __identifier keyword is really nice: it allows
using keywords as identifiers. This is useful in interoperability. For
example, if you had this in a .c file:
int class;
You could then do this from a .cpp file to access it:
extern "C" int __identifier(class);
__identifier also may take a literal string as a parameter, allowing weird
characters in identifiers. I would say that the effect of using a literal
string that is neither a legal C++ identifier nor a C++ keyword (i.e.
something that'd work without being a string) has unspecified behavior,
leaving it to the implementation to decide whether such a thing is
meaningful or an error. This literal string feature can be used to access
mangled symbol names if used in conjunction with extern "C", or could be
used to put dollar signs in identifiers. And yes,
__identifier(__identifier) is legal.
There is actually an interesting secondary use for __identifier: detecting
whether a type is native. For example, this will return true whenever
Microsoft gets around to implementing char16_t for real:
class _is_wchar_t_native_helper
{
struct dummy;
typedef dummy *__identifier(wchar_t);
struct inner
{
typedef wchar_t direct;
};
friend struct is_wchar_t_native;
};
struct is_wchar_t_native
: std::integral_constant<bool, !std::is_same<
_is_wchar_t_native_helper::inner::direct,
_is_wchar_t_native_helper::__identifier(wchar_t)>::value>
{
};
Of course, I wouldn't call it "__identifier". Maybe _Identifier, if we
could get C on board. Assuming that this proposal isn't hated =)
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_420_1015641013.1414698730942
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I think Visual Studio's __identifier keyword is really nic=
e: it allows using keywords as identifiers. This is useful in interop=
erability. For example, if you had this in a .c file:<br><br><div cla=
ss=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-co=
lor: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap:=
break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">class</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>You could then d=
o this from a .cpp file to access it:<br><br><div class=3D"prettyprint" sty=
le=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187=
); border-style: solid; border-width: 1px; word-wrap: break-word;"><code cl=
ass=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">extern</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"=
styled-by-prettify">"C"</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> __=
identifier</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">class</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></cod=
e></div><br>__identifier also may take a literal string as a parameter, all=
owing weird characters in identifiers. I would say that the effect of=
using a literal string that is neither a legal C++ identifier nor a C++ ke=
yword (i.e. something that'd work without being a string) has unspecified b=
ehavior, leaving it to the implementation to decide whether such a thing is=
meaningful or an error. This literal string feature can be used to a=
ccess mangled symbol names if used in conjunction with extern "C", or could=
be used to put dollar signs in identifiers. And yes, __identifier(__=
identifier) is legal.<br><br><br>There is actually an interesting secondary=
use for __identifier: detecting whether a type is native. For exampl=
e, this will return true whenever Microsoft gets around to implementing cha=
r16_t for real:<br><br><div class=3D"prettyprint" style=3D"background-color=
: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid=
; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><d=
iv class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by=
-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> _is_wchar_t_native_helper<br></span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> dummy</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">typedef</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> dummy </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>__identifier</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">wchar_=
t</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> inner<br>&nb=
sp; </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbs=
p; </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">typedef</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">wchar_t</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
direct</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &n=
bsp; </span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &n=
bsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">frien=
d</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> is_wchar_t_native</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> is_wchar_t_native<br> </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">integral_constant</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">bool</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">!</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:=
:</span><span style=3D"color: #000;" class=3D"styled-by-prettify">is_same</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br> =
_is_wchar_t_native_helper</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">inner</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">direct</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&=
nbsp; _is_wchar_t_native_helper</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">__identifier</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">wchar_t</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)>::</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">value</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></=
code></div><br>Of course, I wouldn't call it "__identifier". Maybe _I=
dentifier, if we could get C on board. Assuming that this proposal is=
n't hated =3D)<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_420_1015641013.1414698730942--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Thu, 30 Oct 2014 20:14:38 -0700
Raw View
On Thursday 30 October 2014 12:52:10 Myriachan wrote:
> extern "C" int __identifier(class);
>
> __identifier also may take a literal string as a parameter, allowing weird
> characters in identifiers. I would say that the effect of using a literal
> string that is neither a legal C++ identifier nor a C++ keyword (i.e.
> something that'd work without being a string) has unspecified behavior,
> leaving it to the implementation to decide whether such a thing is
> meaningful or an error. This literal string feature can be used to access
> mangled symbol names if used in conjunction with extern "C", or could be
> used to put dollar signs in identifiers. And yes,
> __identifier(__identifier) is legal.
How about an identifier containing the closing parenthesis? You probably want
to have this as a string literal.
With GCC:
extern "C" int class_() asm("class");
extern "C" int closingparen() asm("(");
Or, maybe just use the backtick like SQL does:
SELECT `SELECT` FROM `FROM`;
But aside from external names, what use would this have? I'm not sure I
understood your example for wchar_t/char16_t and, to be honest, it's not
relevant because the standard can assume that the implementation fully
implements the standard.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
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/.
.
Author: Myriachan <myriachan@gmail.com>
Date: Thu, 30 Oct 2014 22:10:07 -0700 (PDT)
Raw View
------=_Part_1320_1561302656.1414732207988
Content-Type: text/plain; charset=UTF-8
On Thursday, October 30, 2014 8:14:46 PM UTC-7, Thiago Macieira wrote:
>
> How about an identifier containing the closing parenthesis? You probably
> want
> to have this as a string literal.
>
> With GCC:
>
> extern "C" int class_() asm("class");
> extern "C" int closingparen() asm("(");
>
>
Visual C++ equivalent, in theory:
extern "C" int __identifier(class)();
extern "C" int __identifier("(")();
> Or, maybe just use the backtick like SQL does:
>
> SELECT `SELECT` FROM `FROM`;
>
>
I actually prefer the MySQL `` style to __identifier =) (It's
implementation-specific, by the way. Oracle uses double quotes, and
Microsoft SQL Server I believe uses square brackets...?)
> But aside from external names, what use would this have? I'm not sure I
> understood your example for wchar_t/char16_t and, to be honest, it's not
> relevant because the standard can assume that the implementation fully
> implements the standard.
>
>
Certainly; it was just a little trick you can do in the Visual C++ style,
and isn't something needed in the Standard. It doesn't work with GCC or
Clang's __asm__ because those don't modify the name of the variable, only
its object symbol. It's like creating a legal-identifier alias, whereas
MSVC's __identifier actually makes the identifier name be "class" and will
show it in error messages that way and such.
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_1320_1561302656.1414732207988
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Thursday, October 30, 2014 8:14:46 PM UTC-7, Thiago Mac=
ieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">How about an ident=
ifier containing the closing parenthesis? You probably want=20
<br>to have this as a string literal.
<br>
<br>With GCC:
<br>
<br>extern "C" int class_() asm("class");
<br>extern "C" int closingparen() asm("(");
<br>
<br></blockquote><div><br>Visual C++ equivalent, in theory:<br><br>extern "=
C" int __identifier(class)();<br>extern "C" int __identifier("(")();<br>&nb=
sp;</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: =
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Or, maybe just use th=
e backtick like SQL does:
<br>
<br>SELECT `SELECT` FROM `FROM`;
<br>
<br></blockquote><div><br>I actually prefer the MySQL `` style to __identif=
ier =3D) (It's implementation-specific, by the way. Oracle uses=
double quotes, and Microsoft SQL Server I believe uses square brackets...?=
)<br> </div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">But aside fro=
m external names, what use would this have? I'm not sure I=20
<br>understood your example for wchar_t/char16_t and, to be honest, it's no=
t=20
<br>relevant because the standard can assume that the implementation fully=
=20
<br>implements the standard.
<br>
<br></blockquote><div><br>Certainly; it was just a little trick you can do =
in the Visual C++ style, and isn't something needed in the Standard. =
It doesn't work with GCC or Clang's __asm__ because those don't modify the =
name of the variable, only its object symbol. It's like creating a le=
gal-identifier alias, whereas MSVC's __identifier actually makes the identi=
fier name be "class" and will show it in error messages that way and such.<=
br><br>Melissa<br></div></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_1320_1561302656.1414732207988--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Fri, 31 Oct 2014 13:48:14 +0200
Raw View
On 30 October 2014 21:52, Myriachan <myriachan@gmail.com> wrote:
> I think Visual Studio's __identifier keyword is really nice: it allows using
> keywords as identifiers. This is useful in interoperability. For example,
> if you had this in a .c file:
>
> int class;
>
> You could then do this from a .cpp file to access it:
>
> extern "C" int __identifier(class);
I don't think the benefit of such a facility outweighs its cost. The use cases
for such obnoxious C code are, I believe, rare.
> There is actually an interesting secondary use for __identifier: detecting
> whether a type is native. For example, this will return true whenever
I think we already have sufficient type traits for that.
> Of course, I wouldn't call it "__identifier". Maybe _Identifier, if we
> could get C on board. Assuming that this proposal isn't hated =)
-1 Hates It.
--
---
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/.
.
Author: Douglas Boffey <douglas.boffey@gmail.com>
Date: Fri, 31 Oct 2014 08:16:52 -0700 (PDT)
Raw View
------=_Part_334_385877390.1414768612528
Content-Type: text/plain; charset=UTF-8
On Friday, 31 October 2014 11:48:16 UTC, Ville Voutilainen wrote:
>
>
> > could get C on board. Assuming that this proposal isn't hated =)
>
> -1 Hates It.
>
Ditto.
--
---
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_334_385877390.1414768612528
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Friday, 31 October 2014 11:48:16 UTC, Ville Vou=
tilainen wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><br>> could=
get C on board. Assuming that this proposal isn't hated =3D)
<br>
<br>-1 Hates It.
<br></blockquote><div>Ditto. <br></div></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_334_385877390.1414768612528--
.
Author: Sean Middleditch <sean.middleditch@gmail.com>
Date: Fri, 31 Oct 2014 20:46:28 -0700 (PDT)
Raw View
I don't think it's needed today, but I believe it could be very handy for forward compatibility.
--
---
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/.
.
Author: "Daniel Gutson" <danielgutson@gmail.com>
Date: Sat, 1 Nov 2014 15:59:08 +0000
Raw View
There's a use case I hit too often, but goes well beyond this: interoperabi=
lity with C.
Many times I had to use a C API (specially if it is a low level API) which =
is not C++ valid. Referring to a hardware device by its "class" is very com=
mon (struct class {...}), forcing me to #define class _class before #includ=
ing the C API headers but still requiring a huge amount of PITAness.
I think that addressing these problems would be very useful, I don't think =
__identifier would be a nice solution, but in any case it addresses a very =
small part of it.
Maybe something like #include_c or alike (I'm not even sure it is solvable =
within the cpp scope only).
Anyway, it's worth to consider.
Daniel.
-----Original Message-----
From: Sean Middleditch <sean.middleditch@gmail.com>
Date: Fri, 31 Oct 2014 20:46:28=20
To: <std-proposals@isocpp.org>
Reply-To: std-proposals@isocpp.org
Subject: [std-proposals] Visual C++'s __identifier keyword
I don't think it's needed today, but I believe it could be very handy for f=
orward compatibility.
--=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/.
--=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/.
.