gnustep-dev
[Top][All Lists]
Advanced

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

Re: char vs. unsigned char


From: Wolfgang Lux
Subject: Re: char vs. unsigned char
Date: Fri, 13 Mar 2015 10:32:04 +0100

Hi Riccardo,

> a developer question. I got LuserNET working again! another application 
> almost saved from bitrot :)
> 
> I get however a lot of warnings about signedess in char*. In several palces 
> data buffers are specified as unsigned char, while in other places data 
> coming from those buffers is used as char*, including when passing to C 
> functions like atoi().
> 
> My simple knowledge would say that usually one can just use char* when 
> treating the content as binary or as string. While signeddess matters when 
> numbers are stored.
> 
> I converted many buffers and structs. Everything continues to work as far as 
> I can see.
> 
> Could someone comment? check my patch at least by skimming over it?
> 
> I wonder why these were declared as unsigned as first.

I would assume that it is done to get sign extension right when a char is 
extended to an int (e.g., when passing it as an argument to function). And your 
patch does get this wrong in at least one place (I haven't looked for more):
        {
-               unsigned char *a=(unsigned char *)&addr.sin_addr;
+               char *a=(char *)&addr.sin_addr;
                [rec nntp_message:
                        [NSString stringWithFormat: _(@"Connecting to 
%i.%i.%i.%i:%i..."),
                                a[0],a[1],a[2],a[3],port]];
On a system where char is signed char by default (IIRC true on, e.g., NetBSD 
x86) and you are connecting to an IP like 192.168.1.1, this would incorrectly 
show up as 'Connecting to -64.-88.1.1...' with your patch.

Wolfgang




reply via email to

[Prev in Thread] Current Thread [Next in Thread]