home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!fjh
- From: fjh@cs.mu.OZ.AU (Fergus Henderson)
- Subject: Re: Small Language Wanted
- Message-ID: <9224117.23480@mulga.cs.mu.OZ.AU>
- Organization: Computer Science, University of Melbourne, Australia
- References: <DAVIS.92Aug23010605@pacific.mps.ohio-state.edu> <H.3lvmyc56w&A@lionbbs.bs.open.de> <1992Aug27.181926.5677@alchemy.chem.utoronto.ca> <9224107.5975@mulga.cs.mu.OZ.AU> <DAVIS.92Aug27211418@pacific.mps.ohio-state.edu> <DAVIS.92Aug28015332@pacific.mps.ohio-state.edu>
- Date: Fri, 28 Aug 1992 07:58:25 GMT
- Lines: 70
-
- davis@pacific.mps.ohio-state.edu ("John E. Davis") writes:
-
- [Example showing problems with K&R C not having prototypes]
-
- >It has been pointed out to me by several people that this is compiler
- >dependent and the a true ansi compliant answer will produce the correct
- >answer. This is because instead of a declaration like:
- >
- > extern double pow(/* double, double */);
- >
- >the ANSI declaration would read:
- >
- > extern double pow(double, double);
- >
- >
- >This has the effect of performing the correct typecasts before calling the
- >function `pow'.
- >
- >But then this behavior contradicts something else the other poster said:
- >
- > >pow(a,i)
- >
- > >in your code, and "i" happens to be an integer then it can emit code to
- > > - call the standard pow() function after convertin
- > > i to a double
- > > - call a special function the calculates doubles to
- > > integer powers
- > > - calculate the exponentiation using inline code.
- > >Ie. it can make EXACTLY the same optimizations that Fortran compilers
- > >make when they see a**i.
- > >[...]
- > >Any function that is part of the standard library is a "built-in"
- > >function.
-
- No, they are not contradictory.
- The compiler must generate code that has the *same effect* as
- simply converting to double and then calling pow(), but it is
- quite free to substitute any equivalent code which may be more
- efficient, for example by converting the call to a couple of inline
- multiplications.
-
- >This seems to imply that if I do:
- >
- >int i = 4; float y, x = 2.0; y = pow(x,i)
- >
- >The code for pow will recognize that 4.0 = (double) i is equivalent to the
- >integer 4 and will generate code like:
- >
- > return(tmp = 2.0 * 2.0, tmp * tmp);
- >
- >as opposed something like
- >
- > return( exp ( 4.0 * log(2.0));
- >
- >Are there really any existing C compliers out there that perform such
- >optimizations?
-
- Both GNU C and Microsoft C will inline some standard library functions,
- even in C (not C++) programs. This is generally used for simple functions
- like strcpy, memcpy, strcmp, etc. I don't know of any compilers that
- apply strength reduction optimizations to calls to pow(), but it
- is certainly allowed by the standard and would not be difficult to
- implement.
-
- --
- Fergus Henderson (fjh@munta.cs.mu.OZ.AU) .sig truncated to avoid bugs in system
- software that result in duplication of .sig apparently at random (AARRGGHHH!!!)
- --
- Fergus Henderson (fjh@munta.cs.mu.OZ.AU) .sig truncated to avoid bugs in system
- software that result in duplication of .sig apparently at random (AARRGGHHH!!!)
-