🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

[BUG?] CW6, signed chars, comparisons

#1341
From: Rob Barris
Date: Fri, 10 Nov 2000 00:00
72 lines
2426 bytes
   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.

---
> See this code:
> 
> --- snip
> 
> /*
>  *  � 1997-2000 Metrowerks Corp.
>  *
>  *  Questions and comments to:
>  *       <mailto:support@metrowerks.com>
>  *       <http://www.metrowerks.com/>
>  */
> 
> #include <stdio.h>
> 
> #define  kLimit   200
> 
> void funny( char x );
> void funny( char x )
> {
>    if (x < kLimit)                /* problem here */
>       printf("\nless");
>    else
>       printf("\nnot less");
>    
> }
> 
> int main( void ) {
>    printf("Hello World.\n");
>    
>    funny(0);
>    funny(1);
>    
>    return 0;
> }
> 
> 
> --- snip
> 
> 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?
> 
> Can I not compare a char against the number 200?
> 
> I know of course that the max positive value of a signed char is 127, 
> which above I am not exceeding, the confusion appears to take place on 
> the one line "if (x<kLimit)".
>    It seems to me that CW6/Win is demoting the number 200 to signed char, 
>    instead of promoting 'x' to int, the obvious sign bit confusion 
>    ensues.
> 
> This actually bit me on some code that was working fine on CW5 on WIndows 
> and broke under CW6.
> 
> Educate me please :)
> 

Rob
Technical Details
Message-ID: <rbarris-9F1405.11512510112000@news.intelenet.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10bcce,c34fc3d37319c86,start
X-Google-Attributes: gid10bcce,public
X-Google-Thread: f635e,c34fc3d37319c86,start
X-Google-Attributes: gidf635e,public
X-Google-Thread: fd047,c34fc3d37319c86,start
X-Google-Attributes: gidfd047,public
From: Rob Barris <rbarris@quicksilver.com>
Subject: [BUG?] CW6, signed chars, comparisons
Date: 2000/11/10
Message-ID: <rbarris-9F1405.11512510112000@news.intelenet.net>
X-Deja-AN: 692142416
X-Complaints-To: abuse@intelenet.net
X-Trace: newsfeed.intelenet.net 973885883 207.38.32.18 (Fri, 10 Nov 2000 11:51:23 PST)
Organization: Quicksilver Software Inc.
User-Agent: MT-NewsWatcher/3.0 (PPC)
NNTP-Posting-Date: Fri, 10 Nov 2000 11:51:23 PST
Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac,codewarrior.windows