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

  1. Path: sparky!uunet!gatech!destroyer!caen!spool.mu.edu!olivea!sgigate!odin!fido!shankar
  2. From: shankar@sgi.com (Shankar Unni)
  3. Newsgroups: comp.sys.hp
  4. Subject: Re: that HPUX cc compiler
  5. Message-ID: <pejsjp4@fido.asd.sgi.com>
  6. Date: 4 Sep 92 21:44:06 GMT
  7. References: <1992Aug31.104950.1108@bohra.cpg.oz.au> <4722@prcrs.prc.com> <3939@sicsun.epfl.ch>
  8. Sender: news@fido.asd.sgi.com (Usenet News Admin)
  9. Organization: Silicon Graphics, Inc.
  10. Lines: 44
  11.  
  12. In article <3939@sicsun.epfl.ch> lecom@slhp1.epfl.ch (Claude Lecommandeur) writes:
  13.  
  14. >    I have seen this behaviour before, i mistakenly gave the actual structure
  15. >instead of its address as a parameter to a function call and it worked when
  16. >compiled without -O and broke with -O. (it's hard to debug because it works
  17. >with -g). In this case, it is definetely not the optimiser which is broken,
  18. >but the compiler itself. It looks like it tries to be too much clever.
  19.  
  20. No, it's not - it's doing a perfectly reasonable thing.
  21.  
  22. You are passing a struct by value to a function whose prototype is not
  23. declared (I'm talking K&R compiles here for the moment). Since that's
  24. a perfectly legal thing to do, the compiler does so. It just happens
  25. that the way the HP compiler does it is to pass in the address of the
  26. structure to the callee, *which is supposed to make a local copy
  27. immediately* (automatically, that is, if the parameter is declared
  28. correctly as a struct by value).
  29.  
  30. If the target declares it as a struct by reference, you *could* have a
  31. situation where the struct passed by value gets modified by the callee.
  32. As is the case with the fread call.
  33.  
  34. However, back at the point of call, the optimizer is pretty confident
  35. that the struct is not modified by the call (hey, it was passed by
  36. value, wasn't it?). Which is why it thinks the assignment is
  37. loop-invariant.
  38.  
  39. In this case, I agree that it may have been wiser to make the copy at
  40. the point of call rather than at the point of entry - that way, the
  41. above program would not have worked either optimized or unoptimized,
  42. and the user would have been alerted.
  43.  
  44. Still, all these are just ordinary implementation decisions, and just
  45. happen to have odd consequences if you break the rules in a way that
  46. the compiler can't detect.
  47.  
  48. Answer(s):
  49.  
  50.   - (pre-ANSI): Lint it once, Lint it twice, Lint it once again....
  51.   - (brave new ANSI world): cc -Aa, *and use those **** prototypes!!*
  52.  
  53. --
  54. Shankar Unni                E-Mail:    shankar@sgi.com
  55. Silicon Graphics Inc.            Phone:    +1-415-390-2072
  56.