home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!rutgers!modus!gear!cadlab!martelli
- From: martelli@cadlab.sublink.org (Alex Martelli)
- Newsgroups: comp.sys.hp
- Subject: Re: that HPUX cc compiler
- Message-ID: <1992Sep09.093710.3411@cadlab.sublink.org>
- Date: 9 Sep 92 09:37:10 GMT
- References: <1992Aug31.104950.1108@bohra.cpg.oz.au> <4722@prcrs.prc.com> <3939@sicsun.epfl.ch> <pejsjp4@fido.asd.sgi.com>
- Organization: CAD.LAB S.p.A., Bologna, Italia
- Lines: 56
-
- shankar@sgi.com (Shankar Unni) writes:
- ...[on why passing a struct "works" as well as passing its address]...
- :No, it's not - it's doing a perfectly reasonable thing.
-
- I fully agree on this.
-
- :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).
-
- I think this is a very good choice of calling conventions.
-
- :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.
-
- I disagree with you on this. Many times the called function will not
- need to change the struct argument it was passed; in this case an
- otherwise futile memory-to-memory copy is avoided by HP's calling
- conventions, if the compiler is able to get enough alias info when
- doing the called routine to omit the copy. Even when it can't...:
-
- struct whatever { int first, second, third, fourth; }
-
- int calledrout(struct whatever it, int *tricky) {
- (&tricky)++;
- return it.first+it.third;
- }
-
- ...it may be able to reorder, or snatch needed fields from the structure
- BEFORE the possible side effects due to aliasing. Even if the
- compiler can't do these optimizations today, by choosing this calling
- convention it seems to me that HP has kept the door open to the chance
- of introducing them painlessly in the future, i.e. without breaking
- compatibility between code made by the old compiler and code made by
- the old one.
-
- Computers already spend too much time just copying reams of data from
- here to there "just in case"...:-), that I believe a calling convention
- designed to help with this should be praised, even if it does make it
- harder to catch a nasty user's bug! After all as you say yourself the
- use of function prototypes would have squashed this bug right now!
-
- :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.
-
- Again, on this we fully agree.
- --
- Email: martelli@cadlab.sublink.org Phone: ++39 (51) 6130360
- CAD.LAB s.p.a., v. Ronzani 7/29, Casalecchio, Italia Fax: ++39 (51) 6130294
-