home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!utcsri!helios.physics.utoronto.ca!alchemy.chem.utoronto.ca!mroussel
- From: mroussel@alchemy.chem.utoronto.ca (Marc Roussel)
- Subject: Re: Small Language Wanted
- Message-ID: <1992Aug27.181926.5677@alchemy.chem.utoronto.ca>
- Organization: Department of Chemistry, University of Toronto
- References: <DAVIS.92Aug23010605@pacific.mps.ohio-state.edu> <H.3lvmyc56w&A@lionbbs.bs.open.de>
- Date: Thu, 27 Aug 1992 18:19:26 GMT
- Lines: 61
-
- In article <H.3lvmyc56w&A@lionbbs.bs.open.de> UweKloss@lionbbs.bs.open.de
- writes:
- >In <DAVIS.92Aug23010605@pacific.mps.ohio-state.edu>, "John E. Davis" writes:
- >> In addition, C has nothing equivalent to Fortrans **
- >> operator nor does it have complex types.
- >The differeces between code the compiler generates and
- >the one that is linked as a library or inserted by the
- >preprocessor.
-
- That is a big difference! Consider the following Fortran program:
-
- integer i
- double precision a,b
- a = 4.2
- b = 9.3
- i = 10
- write(*,*)a**i,a**b
- END
-
- The compiler, faced with such a program, examines the types of the
- arguments and generates completely different code to do the two
- exponentiations; certainly, one calculation can be expressed exactly in
- terms of multiplications while the other cannot. It may be more
- efficient or more accurate to do it one way or the other and the
- compiler can choose a calculation method which reflects current thinking
- on this sort of problem.
- Now consider an equivalent piece of code, written in C:
-
- void main(){
- int i;
- double a,b;
- a = 4.2;
- b = 9.3;
- i = 10;
- printf(pow(a,(double) i),pow(a,b));
- }
-
- (You'll forgive me, I hope, for getting the C idiom slightly wrong.
- The one manual I have at hand right now is less than entirely helpful on
- several trivial details. In particular, I'm not at all sure that the
- cast of i to double is entirely kosher, and I think that printf wants a
- format specification. In any event, you get the general idea.) Can the
- compiler play the sorts of tricks which the Fortran compiler was free to
- do? I don't think so. pow() being a library routine, I don't think it
- would be good form (or standard-conforming) for the compiler to guess at
- the programmer's intent and to do anything more than to leave the
- reference to be resolved by the linker. After all, until the library is
- linked in, in principle the compiler knows nothing about any function
- but perhaps its prototype. This particular library function
- expects (I think) two doubles (floats?) and must be passed these.
- That's all there is to it.
- In my opinion, what C lacks to be able to handle these things
- correctly is any concept of a "built-in" function. Fortran knows to
- treat sin(a) and sin(x) differently if a is real and x is double
- precision because knowledge of these primitive functions is built into
- the compiler. C can't do anything like this because of its design. C
- is great for writing wordprocessors, but not so great for scientific
- computing for exactly this sort of reason.
-
- Marc R. Roussel
- mroussel@alchemy.chem.utoronto.ca
-