Re: proper way to create a GString object from an unsigned char *

I'd like to try and summarize, to make sure I get this and to document
what I've learned. Comments, corrections, etc. most welcome!

First of all, thanks to my girlfriend Eva for helping me learn this.

signed and unsigned char are the same width. If numeric data is stored
in either, the numeric range is different. If character data is stored
in either, the "character range" is the same; there are no negative
letters/symbols/characters. In other words, no bits would be necessary
to record signedness if letters/symbols/characters are being stored in
a (signed or unsigned) char sized variable.

Therefore, casting a signed char* to an unsigned char* doesn't have any
effect as long as the char*s point to letters/symbols/character (string)

Stylistically, char should never be allowed to be signed, since it's
designed for characters, not numbers!

On Fri, 23 Jul 2004 17:27:14 -0700, Pawel S. Veselov
<pawel veselov sun com> wrote:
                        Hello, Adam !

On Fri, Jul 23, 2004 at 05:24:14PM -0700, Adam Monsen wrote:
It's OK to cast unsigned char* to signed char* and vice
versa -- if you are working with strings, that is.  If you
were doing arithmetics with the characters (i.e. using them
as small integers), then it could be different.

Might there be any UTF-8 issues when I do this cast?


 Pawel S. Veselov [vps], Sun Microsystems, Inc.
 Staff Engineer, Java Mobile Systems and Services Engineering __ __(O) _ __
   (408) 276-5410   e-mail: Pawel Veselov Sun COM             \ V /| || '  \
fax(408) 276-6090 HomePage:            \_/ |_||_|_|_|

Adam Monsen <adamm wazamatta com>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]