Mail Archives: djgpp/2002/12/12/21:10:43
"Edd Dawson" <hotcakes AT planetquake DOT com> wrote in
message
news:<c5aK9.1738$2E DOT 528 AT news-binary DOT blueyonder DOT co DOT uk>...
> 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
>
> This makes about as much sense as the program's
output! Can anyone
> help me out? I'm pretty sure it's a bug, but I
> wanted to check here
> before making a bug report. I'd be happy to submit >
the source of my
> program if anyone wants to help me further! = )
> If it matters at all, the value of 'raysperpixel'
> was obtained from a string
> using the strtol function from the standard library
> i.e I used the line:
> raysperpixel = (int)strtol(keyvalues[8], NULL, 10);
>
> Any help with this would be great, even if it's
> only to confirm that
> it's a bug!
>
> Edd
>
I think the bug is in your program. I just typed in
the the following program:
#include <stdio.h>
int main()
{
int raysperpixel;
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;
}
I successfully compiled it as follows:
gcc -o test.exe test.c -W -Wall -pedantic
When I executed it, I got the following output:
RPP = -35
-35 is less than 1
In other words, I can't duplicate your error. My
guess is you've mistakenly defined raysperpixel as an
unsigned int instead of an int, which would cause the
error you describe.
Please do the following: Cut and paste (don't
retype!) the above example program and compile and
execute it on your system and see if you get the
correct result. Assuming you do, please provide a
brief example - as brief as mine, please - that we can
actually compile all by itself and that generates your
error. Your test code is not a stand-alone program,
so we have no way of testing it, and as I said, when I
drop your code into the program above, it works fine.
Hope that helps.
Best regards,
Tom
__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com
- Raw text -