Mail Archives: djgpp/1997/10/26/10:15:05
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 -