C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-20-2008, 07:00 AM   #1
Ugly C Lover
 
audinue's Avatar
 
Join Date: Jun 2008
Location: Indonesia
Posts: 462
Exclamation ANSI v.s. Unicode

According to another applications bugs using ANSI functions (e.g. fopen, MessageBoxA) in either Microsoft C Runtime Library or Windows API,...

...1. Should we use the Unicode functions (e.g. _wfopen, MessageBoxW) in our program?

...2. It seems ANSI char is unsigned char (1 byte) and Wide-char is unsigned int (4 bytes), and by using wide-char in our application will increase memory consumptions. Will it decrease performance too?

...3. Any suggestion and/or reference for this?

...4. Thanks for joining this thread ^_^

EDIT:
- Wide-char is unsigned short (2 bytes)
- Replaced Wide <-> Unicode

Last edited by audinue; 06-20-2008 at 07:22 AM.
audinue is offline   Reply With Quote
Old 06-20-2008, 07:03 AM   #2
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
Quote:
Originally Posted by audinue View Post
...1. Should we use the Wide functions (e.g. _wfopen, MessageBoxW) in our program?
Yes, it is recommended to use Unicode, and on Windows, that's Wide characters.
They work with many international characters ANSI does not.
And in these days and times, that's an important thing.

Quote:
...2. It seems ANSI char is unsigned char (1 byte) and Wide-char is unsigned int (4 bytes), and by using wide-char in our application will increase memory consumptions. Will it decrease performance too?
Wide chars are 2 bytes, not 4. It will probably decrease performance, yes, but not on a measurable level, and the advantages of unicode makes it worth that additional speed hit.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 06-20-2008, 07:46 AM   #3
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,439
Actually, since the NT WinAPI works with wide strings internally no matter what (and will convert your narrow strings if you pass them to any API function), using wide characters is likely to be faster.
__________________
All the buzzt!
CornedBee

"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
CornedBee is offline   Reply With Quote
Old 06-20-2008, 08:03 AM   #4
and the hat of sweating
 
Join Date: Aug 2007
Location: Toronto, ON
Posts: 3,122
For production code I'd recommend using Unicode strings, even if you don't have any immediate plans for non-English language support.

For simple test utilities that probably won't be around for very long, ANSI should be fine if you only need English, but Unicode might still be better since you never know when your simple test utility might become popular and used a lot more.
cpjust is offline   Reply With Quote
Old 06-20-2008, 08:06 AM   #5
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
Making your application both ANSI/Unicode safe from the start is what I do.
Using TCHAR and _T or TEXT around your strings will make sure your application will compile as either Unicode or ANSI. Sometimes you may want to switch between the two, and when that moment comes, you'll be fine.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Reply

Tags
memory, wide characters, windows

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unicode v ANSI Calls Davros Windows Programming 3 04-18-2006 09:35 AM
how closely does vc++.net 2003 follow ANSI? krygen C++ Programming 7 09-22-2004 06:48 PM
Wide string to Ansi String Davros C++ Programming 7 08-08-2004 08:40 AM
sigaction() and ANSI C awoodland Linux Programming 4 04-25-2004 01:48 AM
converting Ansi String to double or constant char* value (strtod?) kes103 C++ Programming 5 10-09-2002 12:37 PM


All times are GMT -6. The time now is 02:14 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22