home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / gnu / gcc / bug / 2236 < prev    next >
Encoding:
Text File  |  1992-09-02  |  946 b   |  45 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!tis.llnl.gov!carlson
  3. From: carlson@tis.llnl.gov (John Carlson)
  4. Subject: Increment isn't done before assigment in unoptimized version
  5. Message-ID: <135156@lll-winken.LLNL.GOV>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: Lawrence Livermore National Laboratory
  8. Distribution: gnu
  9. Date: Wed, 2 Sep 1992 09:01:55 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 32
  12.  
  13. Machine: Sparcstation 2
  14. OS: Sun OS 4.1.1
  15. Compiler: gcc-2.2.2
  16.  
  17.  
  18. The follow program gives difference result when compiled with
  19. and without the -O option to gcc.
  20.  
  21. #include <stdio.h>
  22. main ()
  23. {
  24.     int i = 0;
  25.     i = i++;
  26.     printf("should be 1->%d\n", i);
  27. }
  28.  
  29.  
  30. The unoptimized version prints:
  31.  
  32. should be 1->0
  33.  
  34. The optimized version prints:
  35.  
  36. should be 1->1
  37.  
  38. Guess the moral of the story is to use the optimized version.
  39. Either that or I was too tired when programming.
  40. (Yeay! The program works now!)
  41.  
  42. John Carlson
  43. carlson@yottzumm.tis.llnl.gov
  44.  
  45.