🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac.programmer.codewarrior
Article #1344

Re: [BUG?] CW6, signed chars, comparisons

#1344
From: Rob Barris
Date: Sat, 11 Nov 2000 00:00
52 lines
2375 bytes
In article <1ejy14n.67hdw91ccxccaN%remove.fte@writeme.com>, 
remove.fte@writeme.com (Fabrice Truillot) wrote:

> Rob Barris <rbarris@quicksilver.com> wrote:
> 
> > > Built under CW6 on Windows as a console app, I get the output
> > > 
> > > not less
> > > not less
> > > 
> > > Built under CW6 on MacOS/PPC as a console app, I get this:
> > > 
> > > less
> > > less
> > > 
> > > Who's in the wrong here?
> 
> Try this :
> 
> #include <limits>
> 
> /* some other #include needed */
> 
> int main ()
> {
>     if (numeric_limits<char>::is_signed)
>     {
>         std::cout << "char is signed -> -128 ... + 127"
>                   << std::endl;
>     }
>     else
>     {
>         std::cout << "char is'nt signed -> 0 ... 255"
>                   << std::endl;
>     }
> }
> 


   I'm at home and don't have the Windows compiler handy - but no matter 
what the above reports, the 'chars' in question only assume values of 0 
and 1, in the example posted.  Where it gets into trouble is in 
comparison of such a variable to a constant (not another char, just the 
number 200).

   Clearly either the 'char' should be promoted to int, or the 200 gets 
demoted to char (which would cause the problem I saw on CW/Win) before 
the comparison can take place.  I had always thought that in a case like 
this, the smaller type would get promoted to the larger type and avoid 
this problem.

Rob
Technical Details
Message-ID: <rbarris-4F5066.13380111112000@news.irvn1.occa.home.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <rbarris-9F1405.11512510112000@news.intelenet.net> <1ejy14n.67hdw91ccxccaN%remove.fte@writeme.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10bcce,c34fc3d37319c86
X-Google-Attributes: gid10bcce,public
X-Google-Thread: f635e,c34fc3d37319c86
X-Google-Attributes: gidf635e,public
X-Google-Thread: fd047,c34fc3d37319c86
X-Google-Attributes: gidfd047,public
From: Rob Barris <rbarris@quicksilver.com>
Subject: Re: [BUG?] CW6, signed chars, comparisons
Date: 2000/11/11
Message-ID: <rbarris-4F5066.13380111112000@news.irvn1.occa.home.com>
X-Deja-AN: 692507330
References: <rbarris-9F1405.11512510112000@news.intelenet.net> <1ejy14n.67hdw91ccxccaN%remove.fte@writeme.com>
X-Complaints-To: abuse@home.net
X-Trace: news1.alsv1.occa.home.com 973978678 24.11.206.157 (Sat, 11 Nov 2000 13:37:58 PST)
Organization: Quicksilver Software Inc.
User-Agent: MT-NewsWatcher/3.0 (PPC)
NNTP-Posting-Date: Sat, 11 Nov 2000 13:37:58 PST
Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac,codewarrior.windows