Home > Mobile >  Effect of Wide Characters/ Strings on a C Program
Effect of Wide Characters/ Strings on a C Program

Time:12-22

Below is an excerpt from an old edition of the book Programming Windows by Charles Petzold

There are, of course, certain disadvantages to using Unicode. First and foremost is that every string in your program will occupy twice as much space. In addition, you'll observe that the functions in the wide-character run-time library are larger than the usual functions.

Why would every string in my program occupy twice the bytes, should not only the character arrays we've declared as storing wchar_t type do so?

Is there perhaps some condition that if a program is to be able to work with Long values, then the entire program mode it'll operate on is altered?

Usually if we declare a long int, we never fuss over or mention the fact that all ints will be occupying double the memory now. Are strings somehow a special case?

CodePudding user response:

If a string could potentially contain a character outside of the ascii range, you'll have to declare it as a wide string. So most strings in the program will be bigger. Personally, I wouldn't worry about it; if you need Unicode, you need Unicode, and a few more bytes aren't going to kill you.

That seems to be what you're saying, and I agree. But the question is skating the fine line between opinionated and objective.

CodePudding user response:

Unicode have some types : utf8, utf16 utf32. https://en.wikipedia.org/wiki/Unicode. You can check advantage , disadvantage of them to know what situation you should use .

reference: UTF-8, UTF-16, and UTF-32

CodePudding user response:

Why would every string in my program occupy twice the bytes, should not only the character arrays we've declared as storing wchar_t type do so?

As I understand it, it is meant, that if you have a program that uses char *, and now you rewrite that program to use wchar_t *, then it will use (more than) twice the bytes.

  • Related