[comp.sys.mac.programmer] Think C 4.0 comparison problem

murphy@hao.ucar.edu (Graham Murphy) (01/24/90)

I have found that with C code such as:

main()
{
    long int minus1 = -1 ;
    unsigned int one = 1 ;

    if( one < minus1 ) printf( "This gets printed\n" ) ;
}

the printf is executed. It should _not_ be according to my
source of the ANSI standard conversions [1]. The unsigned
int should always be converted to long int for the comparison
as the latter can hold all the values of the former on a Mac.
This would preserve the concept that 1 is greater than -1!

Anyone know what the problem is and any work-arounds?

Graham Murphy

[1]: ANSI C: A Lexical Guide 1988, Mark Williams Company
(New Jersey:Prentice-Hall).
High Altitude Observatory
National Center for Atmospheric Research
P.O. Box 3000, Boulder CO 80307-3000. Ph:(303)497-1565; Fax:(303)497-1137.
INTERNET: murphy@hao.UCAR.EDU; Solar PO: gmurphy@solar.STANFORD.EDU

murphy@hao.ucar.edu (Graham Murphy) (01/24/90)

Ok, so I RTFM'd and tracked down where in the Think C manual
it says that it doesn't use the ANSI rules for integral
promotion. The question still remains:

How the !$!@#$ do I get around this? (Assuming I have this 
problem in about 40 thousand lines of code ported from
a more sensible compiler ...)

Graham


High Altitude Observatory
National Center for Atmospheric Research
P.O. Box 3000, Boulder CO 80307-3000. Ph:(303)497-1565; Fax:(303)497-1137.
INTERNET: murphy@hao.UCAR.EDU; Solar PO: gmurphy@solar.STANFORD.EDU