home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / hp / 10075 < prev    next >
Encoding:
Internet Message Format  |  1992-09-07  |  1.8 KB

  1. Path: sparky!uunet!pmafire!news.dell.com!swrinde!sdd.hp.com!scd.hp.com!cupnews0.cup.hp.com!hppad.waterloo.hp.com!hppad!hpfcso!mjs
  2. From: mjs@hpfcso.FC.HP.COM (Marc Sabatella)
  3. Newsgroups: comp.sys.hp
  4. Subject: Re: that HPUX cc compiler
  5. Message-ID: <7371293@hpfcso.FC.HP.COM>
  6. Date: 4 Sep 92 21:40:31 GMT
  7. References: <1992Aug31.104950.1108@bohra.cpg.oz.au>
  8. Organization: Hewlett-Packard, Fort Collins, CO, USA
  9. Lines: 29
  10.  
  11. In comp.sys.hp, jaenicke@emserver.ee.tu-berlin.de (Lutz Jaenicke) writes:
  12.  
  13. >    while(fread(entry, sizeof entry, 1, u))
  14. >        bogus = entry.ut_time;
  15. > ...
  16. > You could have saved much time, even though I cannot explain why the program
  17. > is running without -O. It must not run!
  18.  
  19. Indeed, there are many examples of programs that fail when optimized due to
  20. problems in the code.  "lint" (or "lintfor" for you Fortran types) can be a big
  21. help here - it will show mismatched parameters, missing parameters,
  22. uninitialized local variables, etc.  ANSI C catches some of these as well, but
  23. can't do the interfile checking that "lint" does, and only checks for
  24. uninitialized variables when compiling optimized.
  25.  
  26. I suspect the reason the example code worked at all unoptimized is that, when
  27. you accidentally passed the structure by value it was placed on the stack (as
  28. are all structures), but fread() itself expected its first argument to be a
  29. pointer, so it took the value from a register (as are all scalar first
  30. arguments).  Unoptimized, that register happened to have the value of the
  31. address of the structure you intended to pass by reference, so fread() put the
  32. data it read into the right place.  Optimized, that register contained some
  33. other value, so fread() tried to put the data somewhere else.
  34.  
  35. --------------
  36. Marc Sabatella (marc@hpmonk.fc.hp.com)
  37. Disclaimers:
  38.     2 + 2 = 3, for suitably small values of 2
  39.     Bill (H.) and Dave (P.) may not always agree with me
  40.