delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/26/10:15:05

Date: Sun, 26 Oct 1997 17:12:49 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Roman Suzi <nuser AT rsuzi DOT pgu DOT karelia DOT ru>
cc: djgpp AT delorie DOT com
Subject: Re: [Q]: unsigned char
In-Reply-To: <ABVqtJqOH3@rsuzi.pgu.karelia.ru>
Message-ID: <Pine.SUN.3.91.971026171222.17911V-100000@is>
MIME-Version: 1.0

On Thu, 23 Oct 1997, Roman Suzi wrote:

> --------------------------------------------------
>   unsigned char a;
> 
>   a = 253;
> 
>   if (a=='\xFD') {
>    ...
>   };
> --------------------------------------------------
> 
>   Compiler gives warning, that
> "comparison is always 0 due to limited range of data type"
> (no matter with or without '-funsigned-char' flag)

Change the offending line to say this:

         if (a == (unsigned char)'\xFD') {

and it will compile without a warning.

You are mixing signed and unsigned integers ('\xFD' is treated as a
signed integer by default), which can get you into VERY subtle bugs.
Avoid this at all costs by always either using unsigned constants,
like in 253U, or, where the syntax doesn't allow it (e.g., you cannot
say '\xFD'U), by casting it explicitly to an unsigned type before
every operation.

> Are there any documents about porting
> programs from BC/TC to DJGPP/gnu C++
> beyond djgppfaq?

This is not a porting problem, it's an ANSI C problem.  Check out the
C language FAQ posted to comp.lang.c group.

- Raw text -


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