delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/28/09:00:26

From: Vik Heyndrickx <Vik DOT Heyndrickx AT rug DOT ac DOT be>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: [Q]: unsigned char
Date: Mon, 27 Oct 1997 09:14:08 +0100
Organization: University of Ghent, Belgium
Lines: 36
Message-ID: <34544D50.639D@rug.ac.be>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 971026171222 DOT 17911V-100000 AT is>
NNTP-Posting-Host: eduserv1.rug.ac.be
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Eli Zaretskii wrote:
> 
> 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 right. Relying on the default setting of -fsigned-char or
-funsigned-char is dangerous. But '\xFD' should be positive when
compiled with -funsigned-char. I tested this and it also *is*. So either
Roman Suzi must use an older buggy compiler or he is using a defective
pgcc or I am missing something.

If you want avoid trouble always use explicit casts in these cases.

-- 
+----------------+
| Vik Heyndrickx |
+----------------+

- Raw text -


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