Thread: ANSI v.s. Wide

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    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.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

    ...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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    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.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unicode v ANSI Calls
    By Davros in forum Windows Programming
    Replies: 3
    Last Post: 04-18-2006, 09:35 AM
  2. how closely does vc++.net 2003 follow ANSI?
    By krygen in forum C++ Programming
    Replies: 7
    Last Post: 09-22-2004, 06:48 PM
  3. Wide string to Ansi String
    By Davros in forum C++ Programming
    Replies: 7
    Last Post: 08-08-2004, 08:40 AM
  4. sigaction() and ANSI C
    By awoodland in forum Linux Programming
    Replies: 4
    Last Post: 04-25-2004, 01:48 AM
  5. Replies: 5
    Last Post: 10-09-2002, 12:37 PM

Tags for this Thread