Article View: comp.sys.mac.programmer.codewarrior
Article #1336Re: [BUG?] CW6, signed chars, comparisons
From: Rob Barris
Date: Mon, 13 Nov 2000 00:00
Date: Mon, 13 Nov 2000 00:00
63 lines
3022 bytes
3022 bytes
In article <rbarris-484498.22494212112000@news.irvn1.occa.home.com>,
Rob Barris <rbarris@quicksilver.com> wrote:
> In article <3A0F6C13.C8BFF209@gorge.net>, brunk@gorge.net wrote:
>
> > MWRon wrote:
> > >
> > > In article <rbarris-9F1405.11512510112000@news.intelenet.net>, Rob
> > > Barris
> > > <rbarris@quicksilver.com> wrote:
> > >
> > > > I mailed this one into Metrowerks support but haven't seen a real
> > > >response yet. Wonder what all you readers think about it. This
> > > >actually caused a bug on some code I was moving from Pro5 to Pro6 on
> > > >Windows.
> > >
> > > This seems to have something to do with chars, I've diiscovered if
> > > you
> > > turn on the use unsigned char it will work for you. That is
> > > probably
> > > better than redoing your entire code until it is fixed.
> >
> > This is good advice.
> >
> > The compiler is free to treat type char as either signed or unsigned.
> > It's up to the programmer to use type signed char or unsigned char
> > explicitly if that is really what is desired. As long as the OP's code
> > was written with these rules in mind, telling the compiler to treat
> > type
> > char as unsigned should work around the compiler bug.
>
> I will have to code it up at work tomorrow and check, but now I
> wonder about this case:
>
> #define kLimit 256
> void funny( char x )
> {
> if (x < kLimit)
> {
> printf("less");
> }
> else
> {
> printf("not less");
> }
> }
>
> main()
> {
> funny(1);
> }
More info.
The above code prints "not less" if kLimit is anything from 129 to
255 inclusive. Once I change kLimit to 256 or higher it prints "less".
(CW6, Windows x86 compiler).
I did another version using 'short' and a kLimit constant of 32769,
no problems there. It seems to specifically affect signed chars being
compared against numeric constants between >=129 and <=255.
Rob
Technical Details
Message-ID:
<rbarris-6FA5D9.13581513112000@news.intelenet.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<rbarris-9F1405.11512510112000@news.intelenet.net> <mwron-1111001051480001@c243286-a.bcreek1.mi.home.com> <3A0F6C13.C8BFF209@gorge.net> <rbarris-484498.22494212112000@news.irvn1.occa.home.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/13 Message-ID: <rbarris-6FA5D9.13581513112000@news.intelenet.net> X-Deja-AN: 693235404 References: <rbarris-9F1405.11512510112000@news.intelenet.net> <mwron-1111001051480001@c243286-a.bcreek1.mi.home.com> <3A0F6C13.C8BFF209@gorge.net> <rbarris-484498.22494212112000@news.irvn1.occa.home.com> Posted-And-Mailed: yes X-Complaints-To: abuse@intelenet.net X-Trace: newsfeed.intelenet.net 974152697 207.38.32.18 (Mon, 13 Nov 2000 13:58:17 PST) Organization: Quicksilver Software Inc. User-Agent: MT-NewsWatcher/3.0 (PPC) NNTP-Posting-Date: Mon, 13 Nov 2000 13:58:17 PST Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac,codewarrior.windows