Thread View: gnu.gcc.bug
3 messages
3 total messages
Started by Scott Beckstead
Wed, 02 Sep 1992 06:33
Bug in cygnus 2.0.1 (2.1 and 2.2.2 of mainstream)
Author: Scott Beckstead
Date: Wed, 02 Sep 1992 06:33
Date: Wed, 02 Sep 1992 06:33
29 lines
1714 bytes
1714 bytes
I am currently porting a cygnus version of gcc (gpp objc etc.) to a new system.
In my libraries (ansi) strcmp return -1 for less than, 1 for greater than and
0 for equality. The spec merely states negative for less than positive for greater
than and 0 for equal. Yet in the file rtl.c There is a code fragment that
looks like this
if(!strcmp(somevalue,someothervalue))
someaction;
This seems like a particularly BAD idea considering the values returned by
this fully ansi compliant library (yes it does change the behavior of
the programs) I have modified my library to fix this but the code
really should be fixed so that a unary not of a non boolean return
is not used as a boolean. Because with the value -1 I'm sure you see the
problem. (!(-1) is 0 but !(1) is -2 and !(0) is -1)
I beleive the intent of this code to be:
if(!(strcmp(somevalue,someothervalue) == 0))
someaction;
the function name is read_rtx()
If there is some other purpose to this code it is undocumented and unclear
what it might be. I am unwilling to make the code change because I do not
fully understand what is happening here. It is quicker for me to modify
the library functions (without degrading ansi compliance) because I KNOW
what their intent is.
Scott
Re: Bug in cygnus 2.0.1 (2.1 and 2.2.2 of mainstream)
Author: Michael Salmon
Date: Thu, 03 Sep 1992 07:47
Date: Thu, 03 Sep 1992 07:47
49 lines
2036 bytes
2036 bytes
In article <X3NgqB3w164w@kryton.UUCP>,
system@kryton.UUCP (Scott Beckstead) writes:
|> I am currently porting a cygnus version of gcc (gpp objc etc.) to a new system.
|> In my libraries (ansi) strcmp return -1 for less than, 1 for greater than and
|> 0 for equality. The spec merely states negative for less than positive for greater
|> than and 0 for equal. Yet in the file rtl.c There is a code fragment that
|> looks like this
|>
|> if(!strcmp(somevalue,someothervalue))
|> someaction;
|>
|> This seems like a particularly BAD idea considering the values returned by
|> this fully ansi compliant library (yes it does change the behavior of
|> the programs) I have modified my library to fix this but the code
|> really should be fixed so that a unary not of a non boolean return
|> is not used as a boolean. Because with the value -1 I'm sure you see the
|> problem. (!(-1) is 0 but !(1) is -2 and !(0) is -1)
I think that you are confusing ! with ~ as I hope that this shows.
eos6c02 tmp 11 > cat testcode.c
#include <stdio.h>
int main()
{
int i;
for ( i = -1; i <= 1; ++i)
printf( "!(%2d) == %2d, ~(%2d) == %2d.\n", i, !i, i, ~i);
return 0;
}
eos6c02 tmp 12 > testcode
!(-1) == 0, ~(-1) == 0.
!( 0) == 1, ~( 0) == -1.
!( 1) == 0, ~( 1) == -2.
In C, 0 is false everything else is true.
--
Michael Salmon
#include <standard.disclaimer>
#include <witty.saying>
#include <fancy.pseudo.graphics>
Ericsson Telecom AB
Stockholm
Re: Bug in cygnus 2.0.1 (2.1 and 2.2.2 of mainstream)
Author: Robert Earl
Date: Thu, 03 Sep 1992 11:00
Date: Thu, 03 Sep 1992 11:00
30 lines
1634 bytes
1634 bytes
system@kryton.UUCP (Scott Beckstead) writes: | Yet in the file rtl.c There is a code fragment that | looks like this | if(!strcmp(somevalue,someothervalue)) | someaction; | This seems like a particularly BAD idea considering the values returned by | this fully ansi compliant library (yes it does change the behavior of | the programs) I have modified my library to fix this but the code | really should be fixed so that a unary not of a non boolean return | is not used as a boolean. Because with the value -1 I'm sure you see the | problem. (!(-1) is 0 but !(1) is -2 and !(0) is -1) What on earth are you talking about? The "!" operator NEVER returns ANYTHING but 0 or 1. Maybe you're thinking about the "~" operator. | I beleive the intent of this code to be: | if(!(strcmp(somevalue,someothervalue) == 0)) | someaction; Well, you're wrong, and you've just introduced a bug. -- "If you've got a pig that likes jumping fences, | robert earl you have to make its fence a lot higher all at | rearl@ucsd.edu once -- if you do it by increments, all you're | rearl@piggy.ucsb.edu doing is training a jumping pig." -Henry Spencer|
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads