Article View: comp.sys.mac.programmer.codewarrior
Article #1346Re: [BUG?] CW6, signed chars, comparisons
From: Rob Barris
Date: Mon, 13 Nov 2000 06:49
Date: Mon, 13 Nov 2000 06:49
56 lines
2948 bytes
2948 bytes
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);
}
In short I am wondering, once signed versus unsigned is taken out of
the equation, if it gets it right or not. If it follows past behavior,
it will cast the 256 down to 8 bits and turn it into a zero. Sign not
relevant here.
Any C experts want to come down on the above example as poor code?
Shouldn't I be able to compare a char with an int ?
Rob
Technical Details
Message-ID:
<rbarris-484498.22494212112000@news.irvn1.occa.home.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-xit-03!supernews.com!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news1.alsv1.occa.home.com.POSTED!not-for-mailReferences:
<rbarris-9F1405.11512510112000@news.intelenet.net> <mwron-1111001051480001@c243286-a.bcreek1.mi.home.com> <3A0F6C13.C8BFF209@gorge.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f635e,c34fc3d37319c86 X-Google-Attributes: gidf635e,public X-Google-Thread: 10bcce,c34fc3d37319c86 X-Google-Attributes: gid10bcce,public X-Google-Thread: fd047,c34fc3d37319c86 X-Google-Attributes: gidfd047,public X-Google-ArrivalTime: 2000-11-12 22:49:41 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-xit-03!supernews.com!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news1.alsv1.occa.home.com.POSTED!not-for-mail From: Rob Barris <rbarris@quicksilver.com> Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac,codewarrior.windows Subject: Re: [BUG?] CW6, signed chars, comparisons Organization: Quicksilver Software Inc. References: <rbarris-9F1405.11512510112000@news.intelenet.net> <mwron-1111001051480001@c243286-a.bcreek1.mi.home.com> <3A0F6C13.C8BFF209@gorge.net> User-Agent: MT-NewsWatcher/3.0 (PPC) Message-ID: <rbarris-484498.22494212112000@news.irvn1.occa.home.com> Lines: 56 Date: Mon, 13 Nov 2000 06:49:40 GMT NNTP-Posting-Host: 24.11.206.157 X-Complaints-To: abuse@home.net X-Trace: news1.alsv1.occa.home.com 974098180 24.11.206.157 (Sun, 12 Nov 2000 22:49:40 PST) NNTP-Posting-Date: Sun, 12 Nov 2000 22:49:40 PST