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

  1. Path: sparky!uunet!cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!ukma!rutgers!psinntp!psinntp!pool!ujlh
  2. From: ujlh@pool.info.sunyit.edu (James Henrickson)
  3. Newsgroups: comp.os.linux
  4. Subject: Re: GCC 2.2.2d bug
  5. Message-ID: <1992Sep6.162717.24242@pool.info.sunyit.edu>
  6. Date: 6 Sep 92 16:27:17 GMT
  7. References: <1992Sep4.202913.14346@hippo.ru.ac.za> <1992Sep4.230902.2523@novell.com>
  8. Organization: State University of New York -- Institute of Technology
  9. Lines: 33
  10.  
  11. In article <1992Sep4.230902.2523@novell.com> bboerner@novell.com (Brendan B. Boerner) writes:
  12. >In article <1992Sep4.202913.14346@hippo.ru.ac.za> pi@cs.sun.ac.za writes:
  13. >>I have found that gcc is generating the wrong code for the following
  14. >>code fragment:
  15. >>
  16. >>  int p = 10;
  17. >>  p = p++;
  18. >>
  19. >>From my C background, I have found the value to be 10.  Unfortunately
  20. >>(for the gcc maintainers) the result is 11.
  21. >
  22. >I have this idea that if you posted this to comp.lang.c, Chris Torek or
  23. >someone similar would point out that this is correct behaviour.  My gut
  24. >feeling is that it SHOULD be 11 but I'm not a C guru.
  25.  
  26. Since the value of p isn't used for anything, it looks like the compiler
  27. is optimizing it for you.  Here's another test:
  28.  
  29. printf("%d\n",(p = p++));
  30. printf("%d\n",p);
  31.  
  32. The results should, I think, be:
  33. 10
  34. 11
  35.  
  36. The post-increment and post-decrement operations are performed after
  37. they have been used, such as in "for" loops.
  38.  
  39. -- 
  40. Jim H.
  41. *
  42. * James L. Henrickson
  43. * ujlh@sunyit.edu        "Some day I might have a real .signature!"
  44.