home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / linux / 9883 < prev    next >
Encoding:
Text File  |  1992-09-07  |  2.8 KB  |  68 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!gatech!darwin.sura.net!jvnc.net!primerd.prime.com!tiger1.prime.com!cummings
  3. From: cummings@tiger1.prime.com (Kevin J. Cummings)
  4. Subject: Re: GCC 2.2.2d bug
  5. Message-ID: <1992Sep4.174212@tiger1.prime.com>
  6. Followup-To: comp.lang.c
  7. Sender: usenet@primerd.prime.com (Usenet)
  8. Organization: Prime Computer, Inc.
  9. References:  <1992Sep4.202913.14346@hippo.ru.ac.za>
  10. Date: Fri, 4 Sep 1992 21:42:12 GMT
  11. Lines: 55
  12.  
  13. In article <1992Sep4.202913.14346@hippo.ru.ac.za>, pi@oliver.sun.ac.za (Pieter Immelman) writes:
  14. > I have found that gcc is generating the wrong code for the following
  15. > code fragment:
  16. >   int p = 10;
  17. >   p = p++;
  18. > From my C background, I have found the value to be 10.  Unfortunately
  19. > (for the gcc maintainers) the result is 11.
  20.  
  21. Actually, it depends upon whether or not the post increment happens before
  22. or after the assign of p into p, and if before, then upon whether the old
  23. value of p is saved in a register before the post increment gets done.
  24. Not a construct I would get all upset about.  Anyone writing this kind of code
  25. deserves more flames than the compiler writer who didn't handle it right B^).
  26.  
  27. > gcc -s produces the following:
  28. >     movl $10,-4(%ebp)
  29. >     movl -4(%ebp),%edx
  30. >     movl %edx,-4(%ebp)
  31. >     incl -4(%ebp)
  32. > As I see it the "incl" is done at the wrong place.  It should be done
  33. > right after the value of "p" was used.  The incrementing is done after
  34. > the assignment; in my opinion it must be done right after obtaining the
  35.  
  36. I was under the impression that the increment could be done any time after the
  37. value for the expression was produced.  Has the ANSI C standard defined it any
  38. further than that?  If not, then it really is an implementation defined
  39. result, and may therefore vary from implementation to implementation.  I don't
  40. have my C standard with me right now to say for sure, but surely there are
  41. better problems in LINUX to complain about?  Followups are directed to comp.lang.c.
  42.  
  43. > value...  For more fun, try "p = p++ + p++".  The value should be 21,
  44. > but in this case it is 22!
  45. > Any ideas anyone?
  46. > --
  47. > Pieter Immelman (pi@cs.sun.ac.za)             Telephone: +27 2231 774393
  48. > Department of Computer Science, University of Stellenbosch, South Africa
  49.  
  50. -- 
  51. =================================================================
  52. Kevin J. Cummings                       PrimeService
  53. 20 Briarwood Road                       A Computervision Company
  54. Framingham, Mass.                       500 Old Connecticut Path
  55.                     Framingham, Mass.
  56. Work:  cummings@primerd.Prime.COM
  57. Home:  cummings@kjc386.framingham.ma.us
  58.  
  59. Std. Disclaimer: "Mr. McKittrick, after careful consideration,
  60.           I've come to the conclusion that your new
  61.           defense system SUCKS..."   --  War Games
  62. =================================================================
  63.