Topic: Type of string literal in a linkage specification
Author: James Kanze <james.kanze@gmail.com>
Date: Tue, 19 May 2009 10:01:18 CST Raw View
According to the standard, the syntax of a linkage specification
is:
extern string-literal { declaration-seq[opt] }
or
extern string-literal declaration
I see nothing, however, which restricts the type of string
literal, so what about something like:
extern u8"C" void f() ;
extern R"[C]" void f() ;
or
extern L"C" void f() ;
Are these legal? If so, are they all equivalent to:
extern "C" void f() ;
or not?
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S mard, 78210 St.-Cyr-l' cole, France, +33 (0)1 30 23 00 34
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Jiang <goo.mail01@yahoo.com>
Date: Tue, 19 May 2009 21:40:34 CST Raw View
On May 20, 1:01 am, James Kanze <james.ka...@gmail.com> wrote:
> According to the standard, the syntax of a linkage specification
> is:
> extern string-literal { declaration-seq[opt] }
> or
> extern string-literal declaration
> I see nothing, however, which restricts the type of string
> literal, so what about something like:
> extern u8"C" void f() ;
> extern R"[C]" void f() ;
> or
> extern L"C" void f() ;
>
> Are these legal?
It depends on whether the implementation can recognize it or not.
As we have :
Use of a string-literal other than "C" or "C++" is conditionally
supported, with implementation-defined semantics.
That is, it is an implementation defined behavior.
> If so, are they all equivalent to:
> extern "C" void f() ;
> or not?
Not in my mind.
According to 2.13.4, double quoted "C" and "C++", which are
specified by standard, are not equivalent to any of the above
prefixed string literals.
Regards,
Jiang
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Bart van Ingen Schenau <bart@ingen.ddns.info>
Date: Tue, 19 May 2009 21:41:38 CST Raw View
James Kanze wrote:
> According to the standard, the syntax of a linkage specification
> is:
> extern string-literal { declaration-seq[opt] }
> or
> extern string-literal declaration
> I see nothing, however, which restricts the type of string
> literal, so what about something like:
> extern u8"C" void f() ;
> extern R"[C]" void f() ;
> or
> extern L"C" void f() ;
>
> Are these legal? If so, are they all equivalent to:
> extern "C" void f() ;
> or not?
The C++03 standard has the same syntax of a linkage specification.
As far as I can determine, the C++03 standard does not require an
implementation to accept other string literals than "C" and "C++".
If the compiler recognises the string literal L"C" as a strin naming a
known language, the meaning of 'extern L"C" void f();' is implementation
defined.
If the compiler does not recognise L"C" as a string naming the C
language (or some other known language), a diagnostic is required.
It seems to boil down to implementation defined (or even unspecified)
behaviour.
I don't think this in intended to change with the introduction of the
new forms of string literals.
>
> --
> James Kanze (GABI Software) email:james.kanze@gmail.com
Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://c-faq.com/
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: James Kanze <james.kanze@gmail.com>
Date: Wed, 20 May 2009 15:14:25 CST Raw View
On May 20, 5:41 am, Bart van Ingen Schenau <b...@ingen.ddns.info>
wrote:
> James Kanze wrote:
> > According to the standard, the syntax of a linkage specification
> > is:
> > extern string-literal { declaration-seq[opt] }
> > or
> > extern string-literal declaration
> > I see nothing, however, which restricts the type of string
> > literal, so what about something like:
> > extern u8"C" void f() ;
> > extern R"[C]" void f() ;
> > or
> > extern L"C" void f() ;
> > Are these legal? If so, are they all equivalent to:
> > extern "C" void f() ;
> > or not?
> The C++03 standard has the same syntax of a linkage
> specification. As far as I can determine, the C++03 standard
> does not require an implementation to accept other string
> literals than "C" and "C++".
> If the compiler recognises the string literal L"C" as a strin
> naming a known language, the meaning of 'extern L"C" void
> f();' is implementation defined. If the compiler does not
> recognise L"C" as a string naming the C language (or some
> other known language), a diagnostic is required.
> It seems to boil down to implementation defined (or even
> unspecified) behaviour.
> I don't think this in intended to change with the introduction
> of the new forms of string literals.
The real problem, IMHO, is something like R"[C]", which is
requried to be identical to "C". (Normally, "C" and L"C" mean
something different, at the machine level.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S mard, 78210 St.-Cyr-l' cole, France, +33 (0)1 30 23 00 34
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: James Kanze <james.kanze@gmail.com>
Date: Wed, 20 May 2009 15:12:31 CST Raw View
On May 20, 5:40 am, Jiang <goo.mai...@yahoo.com> wrote:
> On May 20, 1:01 am, James Kanze <james.ka...@gmail.com> wrote:
> > According to the standard, the syntax of a linkage specification
> > is:
> > extern string-literal { declaration-seq[opt] }
> > or
> > extern string-literal declaration
> > I see nothing, however, which restricts the type of string
> > literal, so what about something like:
> > extern u8"C" void f() ;
> > extern R"[C]" void f() ;
> > or
> > extern L"C" void f() ;
> > Are these legal?
> It depends on whether the implementation can recognize it or
> not. As we have :
> Use of a string-literal other than "C" or "C++" is
> conditionally supported, with implementation-defined
> semantics.
> That is, it is an implementation defined behavior.
> > If so, are they all equivalent to:
> > extern "C" void f() ;
> > or not?
> Not in my mind.
> According to 2.13.4, double quoted "C" and "C++", which are
> specified by standard, are not equivalent to any of the above
> prefixed string literals.
That was really part of the question: are "C" and R"[C]"
equivalent (in this context)? They both represent the same
string. If the native encoding is something derived from ASCII
(say ISO 8859-1), then "C" and u8"C" are also the same string
(same type, same contents).
The other part is what the standard means in this context when
it speaks of ``a string-literal other that "C" or "C++"''. I
can see several possible meanings:
-- the token must consist of the exact characters specified,
so even R"[C]" would be "other",
-- the string literal must have the same type and value as the
string literal specified, so R"[C]" would be legal (but not
L"C"), or
-- the string literal must consist of the same sequence of
characters as the one specified (which makes even L"C"
legal).
I suspect that the intent is the first, but I'd really like to
see that confirmed; the second seems to be a very reasonable
interpretation as well.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S mard, 78210 St.-Cyr-l' cole, France, +33 (0)1 30 23 00 34
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]