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