delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/26/10:27:06

Date: Wed, 26 Jan 2000 14:19:36 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Petr Maxa <maxa AT sse-za DOT sk>
cc: djgpp AT delorie DOT com
Subject: Re: signed - unsigned chars
In-Reply-To: <001501bf6710$21cbb840$0307028a@prmivv03>
Message-ID: <Pine.SUN.3.91.1000126141914.6180G-100000@is>
MIME-Version: 1.0
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

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.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019