Date: Wed, 26 Jan 2000 14:19:36 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: Petr Maxa cc: djgpp AT delorie DOT com Subject: Re: signed - unsigned chars In-Reply-To: <001501bf6710$21cbb840$0307028a@prmivv03> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com Errors-To: dj-admin AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Tue, 25 Jan 2000, Petr Maxa wrote: > int main() > { > uchar buf[256]; > > code_message(buf,0x81,(uchar *)"Hello world\n",13); /* 1-st overtyping */ > > if((buf[0]==0xff) && (buf[1]==0x81)) /*!! if we use signed char, this > comparation would be useless !! */ > printf((char*)buf+3); /* 2-nd overtyping */ > return 0; > } I was referring to the last cast, inside `printf': why did you need it? AFAIK, "printf(buf+3)" should work with no problems. Doesn't it? > 2. printf function request the "signed char *" type as the first parameter. AFAIK, printf can do well with unsigned char as well. > For curiosity (or off topic), there is also another problem. If You have > signed char type variable with value 0xff (-1) and You convert it to int, > You get 0xffffffff that is also -1, but in our case it might produce buggy > code. Your code mixes signed and unsigned integral types. This always spells trouble. You should avoid mixing signed and unsigned types at all costs.