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

  1. Xref: sparky comp.lang.c:13183 comp.sys.sun.misc:4073
  2. Path: sparky!uunet!stanford.edu!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torek
  3. From: torek@horse.ee.lbl.gov (Chris Torek)
  4. Newsgroups: comp.lang.c,comp.sys.sun.misc
  5. Subject: Re: sun cc optimization failure
  6. Supersedes: <26042@dog.ee.lbl.gov>
  7. Date: 3 Sep 1992 18:22:15 GMT
  8. Organization: Lawrence Berkeley Laboratory, Berkeley
  9. Lines: 38
  10. Message-ID: <26053@dog.ee.lbl.gov>
  11. References: <1992Sep3.040401.16902@mr.med.ge.com>
  12. Reply-To: torek@horse.ee.lbl.gov (Chris Torek)
  13. NNTP-Posting-Host: 128.3.112.15
  14.  
  15. [N.B.: this article is a replacement for a previous one in which I made
  16. an unwarranted dig at the people at Sun who work on the compilers.  Current
  17. news systems should have deleted the other article, but some of you may
  18. have already seen it or have older or incompatible news systems.  I
  19. hereby apologize to the compiler group at Sun.]
  20.  
  21. In article <1992Sep3.040401.16902@mr.med.ge.com> carl@aslmr-serv.med.ge.com
  22. (Carl Crawford) writes:
  23. >consider the following program:
  24. >
  25. >main() {
  26. >    int i,j,ax;
  27. >    ax = 0;
  28. >    for(i=0;i<3;i++){
  29. >        j = ax * i;
  30. >        puts("in for loop");
  31. >    }
  32. >}
  33.  
  34. This program fails strict conformance by:
  35.  
  36.     A: not including <stdio.h>;
  37.     B: reaching the end of an int-valued function (main()) wihtout
  38.        returning a value.
  39.  
  40. >when compiled with cc (sun os 4.1 on sparc 1+), the code runs thru the
  41. >loop three times. when compiled with the -O flag it only runs once. ...
  42.  
  43. After fixing the two errors above, the program still produces only
  44. one copy of "in for loop" when compiled with the SunOS 4.1 `cc' compiler
  45. using `-O'.
  46.  
  47. >how come the optimization screws up the loop?
  48.  
  49. The only possible answer is now ``because the compiler is broken''.
  50. -- 
  51. In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)
  52. Berkeley, CA        Domain:    torek@ee.lbl.gov
  53.