Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Wide characters (http://www.programmingforums.org/showthread.php?t=14681)

mattireland Dec 4th, 2007 11:33 AM

Wide characters
 
Hi,

I was just wondering what the heck a wide character was? I've never needed to use one....

Thanks very much,

Matt. I

Sane Dec 4th, 2007 11:52 AM

Re: Wide characters
 
Wikipedia is your friend: Wide Characters.

Essentially, it is a datatype used to store any character that could not otherwise be stored with the regular "char" datatype. This is because the number of bits used to distinguish a wide character from other characters exceeds the number of bits that a normal character datatype can store. The specifics of this are beyond me.

Ancient Dragon Dec 4th, 2007 4:02 PM

Re: Wide characters
 
wide characters are used in UNICODE programs, which are programs written for most any language such as Chinese, Japanese, German, Frensh, etc. etc. Many characters in non-English languages can't be represented in one char data type. There is actually a UNICODE standard which specify the width of a UNICODE character and functions to manipulate them, and convert from char* to wchar_t*. The Microsoft compilers have a large set of macros to convert function calls between UNICODE and non-UNICODE compiles. If you use these macros you can compile with or without UNICODE with nearly no changes in the source code.

mattireland Dec 4th, 2007 5:02 PM

Re: Wide characters
 
Brilliant! Thank you very much for your help!

Kuryn Dec 4th, 2007 6:09 PM

Re: Wide characters
 
Also its consider better to use wide characters than ansi characters. The reason why is that behind the scenes, the compiler has to convert from unicode to ansi each time. Which causes a performance hit. So when you build applications always you unicode to be safe from the performance hit on non-unicode apps :)

Ancient Dragon Dec 4th, 2007 6:59 PM

Re: Wide characters
 
>>The reason why is that behind the scenes, the compiler has to convert from unicode to ansi each time
No it does not do that, unless you are using some wierd compiler which does that on its own. The compiler uses UNICODE wide characters only if you define UNICODE in your program. Otherwise it uses standard char ascii character set.

>>So when you build applications always you unicode to be safe from the performance hit on non-unicode apps

Maybe what you mean is that the operating system makes that conversion. I don't know whether that is true or not because I don't know the internals of the MS-Windows operating systems.

Kuryn Dec 4th, 2007 7:41 PM

Re: Wide characters
 
Quote:

However, there are several disadvantages to this. First, calling ANSI functions on NT family systems incurs a performance hit, as the string parameters have to be translated on the way into and/or out of the call to the Unicode version of the function.

Second, the reason Unicode was invented in the first place was to allow for the expression of a wide spectrum of languages within a single character encoding. Sticking to ANSI will leave you back in the field of code-pages, and a limited set of supported languages. Finally, there are several technologies in Windows, most notably COM, that are Unicode only. If you write ANSI-only programs, you will have a lot of conversions to perform, which also impact on performance.
http://www.ddj.com/windows/184416713

look for single built ansi

Ancient Dragon Dec 4th, 2007 9:08 PM

Re: Wide characters
 
I believe that is talking about the operating system, not the compiler. Yes, all versions of WinCE and Mobile 5.0 systems are pure (almost) UNICODE, that is, most of the windows api functions and classes required UNICODE. The compiler for those operating systems still support ascii characters just as any other standard c++ compiler does. I worked with these for 10 years. Windows NT thru Vista support UNICODE but do not require it. In order to display a character on the screen the os probably does convert it to unicode, but the compiler has nothing to do with that.

As for COM, it doesn't require UNICODE either, it can transfer ascii characters just as easily as UNICODE (or bstr). And a bstr can be either unicode or ascii, depending on how the program wants to interpret it.


All times are GMT -5. The time now is 3:54 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC