www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/12/13/02:01:10

Message-ID: <3DF984EB.8010102@earthlink.net>
From: Martin Ambuhl <mambuhl AT earthlink DOT net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0
X-Accept-Language: en-us, en, de, fr, ru, el, zh
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: simple inequality evaluation fails?!?!
References: <c5aK9.1738$2E DOT 528 AT news-binary DOT blueyonder DOT co DOT uk>
Lines: 50
Date: Fri, 13 Dec 2002 06:58:04 GMT
NNTP-Posting-Host: 67.210.12.93
X-Complaints-To: abuse AT earthlink DOT net
X-Trace: newsread2.prod.itd.earthlink.net 1039762684 67.210.12.93 (Thu, 12 Dec 2002 22:58:04 PST)
NNTP-Posting-Date: Thu, 12 Dec 2002 22:58:04 PST
Organization: EarthLink Inc. -- http://www.EarthLink.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Edd Dawson wrote:
> Hi,
> 
> I came across an unexpected result when executing a program I'm writing.
> After tracking it down in the source, I wrote a few lines of test code and
> found that a simple evaluation of an inequality was failing.
> Here is the small chunk of test code from the program I am writing:
> 
> //test code starts here
> 
> printf("\nRPP = %d\n", raysperpixel);
> if(raysperpixel < 1)
>      printf("%d is less than 1\n", raysperpixel);
> else
>      printf("%d is greater than or equal to 1\n", raysperpixel);
> 
> //test code ends here
> 
> raysperpixel is an int (i.e its defined properly).
> Here is the corresponding output:
> 
> RPP = -35
> -35 is greater than or equal to 1

I don't believe you.  Here is a compilable version of your code, together 
with the output:

#include <stdio.h>

int main(void)
{
     int raysperpixel = -35;
     printf("\nRPP = %d\n", raysperpixel);
     if (raysperpixel < 1)
         printf("%d is less than 1\n", raysperpixel);
     else
         printf("%d is greater than or equal to 1\n", raysperpixel);
     return 0;
}


RPP = -35
-35 is less than 1

> 
> This makes about as much sense as the program's output! Can anyone help me
> out? I'm pretty sure it's a bug, 

I'm pretty sure you've got some error in your code.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019