473,851 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The need of Unicode types in C++0x

Hi, I am currently learning QT, a portable C++ framework which comes
with both a commercial and GPL license, and which provides conversion
operations to its various types to/from standard C++ types.

For example its QString type provides a toWString() that returns a
std::wstring with its Unicode contents.

So, since wstring supports the largest character set, why do we need
explicit Unicode types in C++?

I think what is needed is a "unicode" locale or at the most, some
unicode locales.
I don't consider being compatible with C99 as an excuse.
Oct 1 '08
29 2130
On 2008-10-02 06:34:25 -0400, Ioannis Vranos
<iv*****@no.spa m.nospamfreemai l.grsaid:
Pete Becker wrote:
>On 2008-10-01 12:57:27 -0400, Ioannis Vranos
<iv*****@no.sp am.nospamfreema il.grsaid:
>>>
If that system supports Unicode as a system-specific type, why can't
wchar_t be made wide enough as that system-specific Unicode type, in
that system?

It can be. But the language definition doesn't require it to be, and
with many implementations it's not


C++03 mentions:
"Type wchar_t is a distinct type whose values can represent distinct
codes for all members of the *largest* extended character set specified
among the supported *locales* (22.1.1). Type wchar_t shall have the same
size, signedness, and alignment requirements (3.9) as one of the other
integral types, called its underlying type".
There's nothing there that requires wchar_t to be large enough to hold
Unicode code points. Certainly if an implementation supports a Unicode
local, wchar_t has to be large enough to handle those characters. But
the language definition doesn't require Unicode locales.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Oct 2 '08 #21
Pete Becker wrote:
On 2008-10-02 06:34:25 -0400, Ioannis Vranos
<iv*****@no.spa m.nospamfreemai l.grsaid:
>Pete Becker wrote:
>>On 2008-10-01 12:57:27 -0400, Ioannis Vranos
<iv*****@no.s pam.nospamfreem ail.grsaid:
If that system supports Unicode as a system-specific type, why can't
wchar_t be made wide enough as that system-specific Unicode type, in
that system?

It can be. But the language definition doesn't require it to be, and
with many implementations it's not


C++03 mentions:
"Type wchar_t is a distinct type whose values can represent distinct
codes for all members of the *largest* extended character set
specified among the supported *locales* (22.1.1). Type wchar_t shall
have the same
size, signedness, and alignment requirements (3.9) as one of the other
integral types, called its underlying type".

There's nothing there that requires wchar_t to be large enough to hold
Unicode code points. Certainly if an implementation supports a Unicode
local, wchar_t has to be large enough to handle those characters. But
the language definition doesn't require Unicode locales.

Yes, I am talking about the upcoming Unicode character types in C++0x,
in comparison with the Unicode locales alternative.

Oct 2 '08 #22
On 2008-10-02 12:26, Ioannis Vranos wrote:
Erik Wikström wrote:
>>
Because it has been to narrow for 5 to 10 years and the compiler vendor
does not want to take any chances with backward compatibility,


How will it break backward compatibility, if the size of whcar_t changes?
Because the user expects to be able to pack 5 wchar_t into a network-
message of a fixed size, or read a few characters from a specific
position in a binary file. Or any number of reasons where someone have
made assumptions about the size of wchar_t.

--
Erik Wikström
Oct 2 '08 #23
On Oct 2, 6:11 pm, Ioannis Vranos <ivra...@no.spa m.nospamfreemai l.gr>
wrote:
Yannick Tremblay wrote:
[...]
A "Unicode" locale makes no sense because the
locale represent much more than simply the character encoding that is
being used.
http://www.unicode.org/reports/tr35/#Locale
True, but I think Unicode locales could be implemented for characters
only, leaving the rest unchanged (as they are).
For example:
locale::global( locale("english "));
wcin.imbue(loca le("UTF16"));
wcout.imbue(loc ale("UTF16"));
would change only the character set, keeping the rest of the
locale settings as they are either they were previously
defined or they are the default ones.
That's not quite how locales work. What I think your talking
about is a UTF16 codecvt facet. And there are ways of
constructing a local by copying another locale, just replacing a
single facet. Of course, the ctype facet is also affected; part
of the problem in doing this cleanly is that abstractions that
we'd like to keep separate get mixed up. (Note that this can be
a problem even within a pure Unicode environment. Something
like toupper( 'i' ) is locale dependent, and will return a
different character in a Turkish locale.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 2 '08 #24
On Oct 2, 4:27 pm, Ioannis Vranos <ivra...@no.spa m.nospamfreemai l.gr>
wrote:
James Kanze wrote:
And break their existing code base? They're not that
irresponsible (most of them, anyway). And the basic idea
behind wchar_t is that it is suppose to be locale
independent, at least for the encoding.
How would they "break" their existing code base, by adding
some additional locales and even changing the size of wchar_t?
Adding locales is no problem. Changing the size, or anything
involving the behavior of wchar_t breaks real code. Some of the
code is probably poorly written, but convincing your customers
that they are idiots doesn't sell many compilers.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 2 '08 #25
James Kanze wrote:
>
Adding locales is no problem. Changing the size, or anything
involving the behavior of wchar_t breaks real code. Some of the
code is probably poorly written, but convincing your customers
that they are idiots doesn't sell many compilers.

OK, but if their badly-written code is broken, they will fix it.
Oct 2 '08 #26
Ioannis Vranos wrote:
James Kanze wrote:
>Adding locales is no problem. Changing the size, or anything
involving the behavior of wchar_t breaks real code. Some of the
code is probably poorly written, but convincing your customers
that they are idiots doesn't sell many compilers.

OK, but if their badly-written code is broken, they will fix it.
For most of the past ten years I have written code that
had to be compiled using halve a dozen compiler/std lib
combinations on so many platforms. We had the very same
code carry UTF-8 strings on some Linux versions, UTF-16
on Windows, and UTF-32 on OSX and some other Unices. We
have learned to deal with all data types being platform-
dependent and our code needing to adapt.
Still, if your vendor does something stupid (like when VC
suddenly started to throw several 10k of useless warnings
for a 2MLoc code base that used to compile clean), you're
doomed.
And this isn't any different when you got yourself into
the trouble yourself. Even if you know that, 15 years ago,
some (people who had long left the company when you came,
and the company was a very different one back then, and
the code's been bought several times over) did something
stupid, it doesn't mean that, now you have several MLoC
relying on a specific size of some built-in type, you can
spend several man-years fixing this and take another two
releases until the dust has settled and all the bugs you
introduced doing so are fixed. While that would be nice
to do, the customers won't pay for it.

C++ has always respected the gazillions of lines of legacy
code real-world projects have. That's probably a reason
for its success.

Schobi
Oct 2 '08 #27
James Kanze wrote:
On Oct 2, 12:21 pm, Hendrik Schober <spamt...@gmx.d ewrote:
>James Kanze wrote:
[...]
>>In what encoding format? And what if the "usual" encoding for
wstring isn't Unicode (the case on many Unix platforms).
> <curious>
What are those implementations using for 'wchar_t'?
</curious>

EUC. EUC (= Extended Unix Codes) is originally a multi-byte
code, but exists as a 32 bit code as well, see
http://docs.sun.com/app/docs/doc/802...sn?l=en&a=view.
It's apparently the standard encoding for wchar_t under Solaris
and HP/UX, and perhaps elsewhere as well. Thus, LATIN SMALL
LETTER E WITH ACUTE has the code 0x00E9 in Unicode, but
0x30000069 under Solaris. (``printf( "%04x\n", (unsigned
int)L'é''') -- the compiler apparently recognizes my
LC_CTYPE=iso_88 59_1 locale for the file input.)
Thanks!

Schobi
Oct 2 '08 #28
On Oct 2, 9:06 pm, Ioannis Vranos <ivra...@no.spa m.nospamfreemai l.gr>
wrote:
James Kanze wrote:
Adding locales is no problem. Changing the size, or
anything involving the behavior of wchar_t breaks real code.
Some of the code is probably poorly written, but convincing
your customers that they are idiots doesn't sell many
compilers.
OK, but if their badly-written code is broken, they will fix
it.
I don't guess you've ever worked in industry. The authors of
the code will claim that it's the compiler which is broken, and
find one which accepts it.

And of course, some of the code that would break probably isn't
broken. If you have no real portability requirements, and you
have a guarantee that wchar_t contains EUC, what's wrong about
programming against that. And you have that guarantee.

Practically speaking, it's easy to add new features---about the
only thing adding char32_t et al. can break is code which used
those symbols as keywords. Where as the standard, and vendor
specifications are a contract, which you really can't change
without wrecking havoc. And if you're a vendor, loosing sales.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Oct 3 '08 #29
On Oct 2, 9:43 pm, Hendrik Schober <spamt...@gmx.d ewrote:

[...]
C++ has always respected the gazillions of lines of legacy
code real-world projects have. That's probably a reason
for its success.
Were it only so. One of the reasons why there was so much
interest in Java was because it was so difficult to write
portable C++, and because the language was felt to be changing
under you. We've had to rework quite a bit of code, including
reorganizing some, because of two phase look-up, and the
differences between the classical iostream and the standard one
have caused more than a few problems as well.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 3 '08 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
637
by: ^_^ | last post by:
conversion from: a="a"; to a=0x????; If there are many unicode strings to convert, how can I do batch-conversion?
4
2289
by: Luk Vloemans | last post by:
Hey, I'm currently working on a project to get GPS-data onto a PDA. At this stage, I'm already getting data from the device, but my problem is: It's rubbish. At least, it looks as if it were rubbish. example: "`?~?\0?~?~????\0x?x?x?x?x?x~??x?x?xx?\0x?x?" I found patterns in the code I received, so it's just encoded.
33
2702
by: Nikhil Bokare | last post by:
I wanted a C++ compiler which would follow the ANSI C++ standards. If you could tell me an IDE also, it would be more helpful. Thanks.
2
1989
by: Ioannis Vranos | last post by:
Based on a discussion about Unicode in clc++ inside a discussion thread with subject "next ISO C++ standard", and the data provided in http://en.wikipedia.org/wiki/C%2B%2B0x , and with the design ideals: 1. To provide Unicode support in C++0x always and explicitly. 2. To provide support to all Unicode sets out there. I think the implementation of these as:
10
3284
by: himanshu.garg | last post by:
Hi, The following std c++ program does not output the unicode character.:- %./a.out en_US.UTF-8 Infinity:
0
9897
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9747
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11019
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9506
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7906
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5736
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5933
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4549
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4143
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.