home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 13192 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1014 b   |  37 lines

  1. Xref: sparky comp.lang.c:13192 comp.sys.sun.misc:4080
  2. Path: sparky!uunet!mdcbbs!sysjj.mdcbbs.com!selig
  3. Newsgroups: comp.lang.c,comp.sys.sun.misc
  4. Subject: Re: sun cc optimization failure
  5. Message-ID: <1992Sep3.123428.1@sysjj.mdcbbs.com>
  6. From: selig@sysjj.mdcbbs.com
  7. Date: 3 Sep 92 12:34:28 GMT
  8. References: <1992Sep3.040401.16902@mr.med.ge.com>
  9. Organization: McDonnell Douglas M&E, Cypress CA
  10. Nntp-Posting-Host: sysjj
  11. Nntp-Posting-User: selig
  12. Lines: 23
  13.  
  14. > consider the following program:
  15. > main() {
  16. >     int i,j,ax;
  17. >     ax = 0;
  18. >     for(i=0;i<3;i++){
  19. >         j = ax * i;
  20. >         puts("in for loop");
  21. >     }
  22. > }
  23. > when compiled with cc (sun os 4.1 on sparc 1+), the 
  24. > code runs thru the loop three times. when comiled with 
  25. > the -O flag it only runs once. how come the optimization 
  26. > screws up the loop?
  27. > --
  28.           If you're entertaining wild guesses, mine is that the
  29.           compiler picked up that since ax is zero, j will always be
  30.           zero.
  31.  
  32.           Try initializing ax to a non-zero number.
  33.  
  34.  
  35.           Dan
  36.