home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / gnu / gcc / bug / 2249 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.9 KB  |  65 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!eos.ericsson.SE!etxmesa
  3. From: etxmesa@eos.ericsson.SE (Michael Salmon)
  4. Subject: Re: Bug in cygnus 2.0.1 (2.1 and 2.2.2 of mainstream)
  5. Message-ID: <1992Sep3.074701.4145@ericsson.se>
  6. Sender: gnulists@ai.mit.edu
  7. Reply-To: etxmesa@eos.ericsson.se (Michael Salmon)
  8. Organization: Ericsson Telecom AB
  9. References: <X3NgqB3w164w@kryton.UUCP>
  10. Distribution: gnu
  11. Date: Thu, 3 Sep 1992 07:47:01 GMT
  12. Approved: bug-gcc@prep.ai.mit.edu
  13. Lines: 50
  14.  
  15. In article <X3NgqB3w164w@kryton.UUCP>,
  16. system@kryton.UUCP (Scott Beckstead) writes:
  17. |> I am currently porting a cygnus version of gcc (gpp objc etc.) to a new system.
  18. |> In my libraries (ansi) strcmp return -1 for less than, 1 for greater than and
  19. |> 0 for equality.  The spec merely states negative for less than positive for greater
  20. |> than and 0 for equal.  Yet in the file rtl.c There is a code fragment that 
  21. |> looks like this 
  22. |> 
  23. |>     if(!strcmp(somevalue,someothervalue))
  24. |>         someaction;
  25. |> 
  26. |> This seems like a particularly BAD idea considering the values returned by
  27. |> this fully ansi compliant library (yes it does change the behavior of
  28. |> the programs)  I have modified my library to fix this but the code
  29. |> really should be fixed so that a unary not of a non boolean return
  30. |> is not used as a boolean.  Because with the value -1 I'm sure you see the
  31. |> problem.  (!(-1) is 0 but !(1) is -2 and !(0) is -1) 
  32.  
  33. I think that you are confusing ! with ~ as I hope that this shows.
  34.  
  35.  eos6c02 tmp 11 > cat testcode.c
  36. #include <stdio.h>
  37.  
  38. int main()
  39. {
  40.     int i;
  41.  
  42.     for ( i = -1; i <= 1; ++i)
  43.         printf( "!(%2d) == %2d, ~(%2d) == %2d.\n", i, !i, i, ~i);
  44.     
  45.     return 0;
  46. }
  47.  eos6c02 tmp 12 > testcode
  48. !(-1) ==  0, ~(-1) ==  0.
  49. !( 0) ==  1, ~( 0) == -1.
  50. !( 1) ==  0, ~( 1) == -2.
  51.  
  52. In C, 0 is false everything else is true.
  53.  
  54. -- 
  55.  
  56. Michael Salmon
  57.  
  58. #include    <standard.disclaimer>
  59. #include    <witty.saying>
  60. #include    <fancy.pseudo.graphics>
  61.  
  62. Ericsson Telecom AB
  63. Stockholm
  64.  
  65.