home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / hp / 10030 < prev    next >
Encoding:
Text File  |  1992-09-03  |  2.2 KB  |  60 lines

  1. Path: sparky!uunet!wupost!uwm.edu!rutgers!psinntp!psinntp!rsi!prcrs!paul
  2. From: paul@prcrs.prc.com (Paul Hite)
  3. Newsgroups: comp.sys.hp
  4. Subject: Re: that HPUX cc compiler
  5. Message-ID: <4722@prcrs.prc.com>
  6. Date: 2 Sep 92 15:14:42 GMT
  7. References: <1992Aug31.104950.1108@bohra.cpg.oz.au>
  8. Organization: PRC Realty Systems, McLean, VA
  9. Lines: 49
  10.  
  11.  
  12. HP gets a lot of grief from the behavior of their c optimizer.  I'm sure
  13. that some of it is valid.  But a lot of the posts basicly say something
  14. like:
  15.     I've got a program that works without the optimizer and fails
  16.     when I optimize it.  Therefore HP's optimizer is broken.
  17.  
  18. Here's a real live counter-example to that argument.  I wrote a replacement
  19. to w and it worked without the optimizer and failed when I optimized it.
  20. I reduced the program to a tiny example that also failed with the optimizer.
  21. The complete program is below my signature, but here is the important part:
  22.     struct utmp entry;
  23.     while(fread(entry, sizeof entry, 1, u)) {
  24.         bogus = entry.ut_time;
  25. With the optimizer, bogus always had the same value.  Without the optimizer
  26. various correct values are printed.  The problem is the fread.  It should be:
  27.     while(fread(&entry, sizeof entry, 1, u)) {
  28.                 ^
  29. And the optimizer works fine on the corrected program.  Actually it's amazing
  30. that the program works at all the first way.  All of this is on an 847, those
  31. of you on other platforms may get different results with the buggy program.
  32. (Indeed, Steinar Haug found the bug for me as he struggled to get my program
  33. working on a 425!)
  34.  
  35. But my point is that the existence of a program like mine that fails when
  36. optimized does not necessarily prove that the optimizer is broken.  It may
  37. be that the program is broken.
  38.  
  39. Paul Hite   PRC Realty Systems  McLean,Va   paul@prcrs.prc.com    (703) 556-2243
  40.     "We are trying to bring up an Air Traffic Control display on an X window 
  41.       terminal and there seems to be some problems." -- from comp.windows.x
  42. --------------
  43. #include <stdio.h>
  44. #include <sys/stat.h>
  45. #include <utmp.h>
  46. #include <time.h>
  47. time_t bogus;
  48. main ()
  49. {
  50.     FILE *u;
  51.     struct utmp entry;
  52.     u = fopen("/etc/utmp","r");
  53.     while(fread(entry, sizeof entry, 1, u)) {
  54.         bogus = entry.ut_time;
  55.         printf("bogus = %d\n");
  56.     }
  57.     fclose(u);
  58.     exit(0);
  59. }
  60.