By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

Which one is correct?

P: n/a
wchar_t ch2 = L'\u27BA';
wchar_t ch = '\u27BA';

On Visual C++ 2003 SP1, no compiler warnings are given at all. However, ch
!= ch2.

Which one is correct?

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:st*****@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

Jun 12 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
[Answering only in comp.lang.c++, where I read it]

"Maximus" wrote:
wchar_t ch2 = L'\u27BA';
wchar_t ch = '\u27BA';

On Visual C++ 2003 SP1, no compiler warnings are given at all.
However, ch != ch2.

Which one is correct?
The effects of placing a universal-character-name in a narrow
character literal (without the L in front) are implementation-
defined, you better ask in 'microsoft.public.vc.language'. As to
warnings, none required since this is not ill-formed.

I would venture a guess that you need L there to be "correct",
since that makes the character literal to have the type 'wchar_t',
which is what you declare 'ch2'. Without the L, the type of the
character literal is 'char', and how it gets converted into the
'wchar_t' for 'ch' is implementation-defined.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 12 '07 #2

P: n/a
On Jun 12, 9:40 pm, maxi...@microsoft.com ("Maximus") wrote:
wchar_t ch2 = L'\u27BA';
wchar_t ch = '\u27BA';

On Visual C++ 2003 SP1, no compiler warnings are given at all. However, ch
!= ch2.

Which one is correct?
27BA is 10170.
'\u27BA' being of type char, it can't be greater than 255, assuming 8-
bit bytes. So it can't contain 10170.
L'\u27BA' being of type whar_t, which is on all implementations I know
at least 16 bits, it can contain 10170.

Therefore the correct one is the first one.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:st*****@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

Jun 13 '07 #3

P: n/a
Mathias Gaunard wrote:
On Jun 12, 9:40 pm, maxi...@microsoft.com ("Maximus") wrote:
>wchar_t ch2 = L'\u27BA';
wchar_t ch = '\u27BA';

On Visual C++ 2003 SP1, no compiler warnings are given at all.
However, ch != ch2.

Which one is correct?

27BA is 10170.
'\u27BA' being of type char, it can't be greater than 255, assuming 8-
bit bytes. So it can't contain 10170.
<nitpick>
Actually, it's implementation-defined. The standard only guarantees
that the upper value is no less than 127, however (IOW, the char is
at least 8-bits). On a PC 'chars' are 8-bit and ususally signed, so
they cannot contain any values above 127...
</nitpick>
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 13 '07 #4

P: n/a

Victor Bazarov wrote in message...
Mathias Gaunard wrote:
On Jun 12, 9:40 pm, maxi...@microsoft.com ("Maximus") wrote:
wchar_t ch2 = L'\u27BA';
wchar_t ch = '\u27BA';

On Visual C++ 2003 SP1, no compiler warnings are given at all.
However, ch != ch2.

Which one is correct?
27BA is 10170.
'\u27BA' being of type char, it can't be greater than 255, assuming 8-
bit bytes. So it can't contain 10170.

<nitpick>
Actually, it's implementation-defined. The standard only guarantees
that the upper value is no less than 127, however (IOW, the char is
at least 8-bits). On a PC 'chars' are 8-bit and ususally signed, so
they cannot contain any values above 127...
</nitpick>
But (on win, P4):
std::cout<<" sizeof(wchar_t) ="<<sizeof(wchar_t)<<std::endl;
// out: sizeof(wchar_t) =2

--
Bob R
POVrookie
Jun 13 '07 #5

P: n/a
BobR wrote:
Victor Bazarov wrote in message...
><nitpick>
Actually, it's implementation-defined. The standard only guarantees
that the upper value is no less than 127, however (IOW, the char is
at least 8-bits). On a PC 'chars' are 8-bit and ususally signed, so
they cannot contain any values above 127...
</nitpick>

But (on win, P4):
std::cout<<" sizeof(wchar_t) ="<<sizeof(wchar_t)<<std::endl;
// out: sizeof(wchar_t) =2
He talks about char, you talk about wchar_t. Makes no sense.

So I try it, too:
On linux, unknown machine:

std::cout<<" sizeof(double) = "<<sizeof(double)<<std::endl;
// out: sizeof(double) = 8

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Jun 13 '07 #6

P: n/a
On Jun 14, 12:02 am, "BobR" <removeBadB...@worldnet.att.netwrote:
Victor Bazarov wrote in message...
Mathias Gaunard wrote:
On Jun 12, 9:40 pm, maxi...@microsoft.com ("Maximus") wrote:
>wchar_t ch2 = L'\u27BA';
>wchar_t ch = '\u27BA';
>On Visual C++ 2003 SP1, no compiler warnings are given at all.
>However, ch != ch2.
>Which one is correct?
27BA is 10170.
'\u27BA' being of type char, it can't be greater than 255, assuming 8-
bit bytes. So it can't contain 10170.
<nitpick>
Actually, it's implementation-defined. The standard only guarantees
that the upper value is no less than 127, however (IOW, the char is
at least 8-bits). On a PC 'chars' are 8-bit and ususally signed, so
they cannot contain any values above 127...
</nitpick>
But (on win, P4):
std::cout<<" sizeof(wchar_t) ="<<sizeof(wchar_t)<<std::endl;
// out: sizeof(wchar_t) =2
But the type of '\u27BA' is char. So the resulting value must
be in the range CHAR_MIN...CHAR_MAX; by default, with VC++,
-128...127 (but if the /J option is given, 0...255).

The reason he's seeing different values is precisely because the
type of '\u27BA' is char, but the type of L'\u27BA' is wchar_t,
in which the value fits.

--
James Kanze (GABI Software, from CAI) email:ja*********@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

Jun 14 '07 #7

P: n/a
James Kanze wrote:
The reason he's seeing different values is precisely because the
type of '\u27BA' is char, but the type of L'\u27BA' is wchar_t,
in which the value fits.
Nothing precludes \u27BA from fitting in a char. While it is
true of Visual Studio he is using, it's not required by the
language. The 27BA is just a particular ISO character nothing
precludes it from being a valid value in the execution character
set (just not allowed to be part of the basic execution character
set).
Jun 14 '07 #8

P: n/a
Mathias Gaunard wrote:
On Jun 12, 9:40 pm, maxi...@microsoft.com ("Maximus") wrote:
>wchar_t ch2 = L'\u27BA';
wchar_t ch = '\u27BA';

On Visual C++ 2003 SP1, no compiler warnings are given at all. However, ch
!= ch2.

Which one is correct?

27BA is 10170.
'\u27BA' being of type char, it can't be greater than 255, assuming 8-
bit bytes. So it can't contain 10170.
Nothing says that \uXXXX maps directly into a character value. The
number after the u is an ISO 10646 (practically unicode) value. Do
not assume the execution character set is ASCII.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:st*****@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

Jun 14 '07 #9

P: n/a

Thomas J. Gritzan <Ph*************@gmx.dewrote in message ...
BobR wrote:
Victor Bazarov wrote in message...
<nitpick>
Actually, it's implementation-defined. The standard only guarantees
that the upper value is no less than 127, however (IOW, the char is
at least 8-bits). On a PC 'chars' are 8-bit and ususally signed, so
they cannot contain any values above 127...
</nitpick>
But (on win, P4):
std::cout<<" sizeof(wchar_t) ="<<sizeof(wchar_t)<<std::endl;
// out: sizeof(wchar_t) =2

He talks about char, you talk about wchar_t. Makes no sense.
Sorry. Somehow I missed the '\u' in there.
(All I seemed to see was '27BA is 10170'.)

Like: Who put that '\u' in there *after* I read the line? <G>

--
Bob R
POVrookie
Jun 14 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.