home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / linux / 10041 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  2.2 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!news.claremont.edu!ucivax!news.service.uci.edu!cerritos.edu!wilbur!orville!kryton!system
  2. Newsgroups: comp.os.linux
  3. Subject: Re: GCC 2.2.2d bug
  4. Message-ID: <8eToqB1w164w@kryton.UUCP>
  5. From: system@kryton.UUCP (Scott Beckstead)
  6. Date: Sun, 06 Sep 92 09:09:54 PDT
  7. References: <1992Sep4.210545.36040@uservx.plk.af.mil>
  8. Organization: Paradox Alley F&SF BBS 805-492-8789
  9. Lines: 59
  10.  
  11. simonich@uservx.plk.af.mil writes:
  12.  
  13. > In article <1992Sep4.230902.2523@novell.com>, bboerner@novell.com (Brendan B.
  14. > > In article <1992Sep4.202913.14346@hippo.ru.ac.za> pi@cs.sun.ac.za writes:
  15. > >>I have found that gcc is generating the wrong code for the following
  16. > >>code fragment:
  17. > >>
  18. > >>  int p = 10;
  19. > >>  p = p++;
  20. > >>
  21. > >>From my C background, I have found the value to be 10.  Unfortunately
  22. > >>(for the gcc maintainers) the result is 11.
  23. > > 
  24. > > I have this idea that if you posted this to comp.lang.c, Chris Torek or
  25. > > someone similar would point out that this is correct behaviour.  My gut
  26. > > feeling is that it SHOULD be 11 but I'm not a C guru.
  27. > > 
  28. > > Later,
  29. > > Brendan
  30. > > -- 
  31. > > Brendan B. Boerner        Phone: 512/346-8380
  32. > > Internet: bboerner@novell.com    MHS: bboerner@novell
  33. > > Please use ^^^^^^^^^^^^^^^^^ if replying by mail.
  34. > I will admit that it isn't the ASCII C standard but on page 46 of 
  35. > The C Programming Language (second edition) by Kernighan and Ritchie
  36. > they give the specific example:
  37. > "If n is 5, then
  38. >         x = n++;
  39. > sets x to 5, but
  40. >         x = ++n;
  41. > sets x to 6."
  42. > I agree with a previous poster that this code fragment is IMHO, very
  43. > poor code. 
  44.  
  45. Indeed very poor code.  The final result will be 11.  because even if
  46. the assign works properly the increment will still happen.  I know
  47. the the gnu code here works properly.  This kind of bug could be so 
  48. subtle that it might easily never be found.  It is also probably
  49. going to be optimized to merely :
  50.  p++;
  51. instead of having any other effect.  Which is properly the semantic 
  52. equivalent of this code fragment.
  53.  
  54. Scott
  55.  
  56.  
  57.  
  58.   
  59.  
  60.  
  61. System Administrator Paradox Alley  F&SF BBS and Usenet News/Mail 
  62. 805-492-8789  Thousand Oaks, Ca. The Place For Science Fiction and Fantasy
  63. "Spin My Nipple Nuts and Send Me to Alaska!" Kryten, Red Dwarf
  64.  
  65.