Xref: utzoo comp.lang.fortran:4238 comp.lang.c:34422 Newsgroups: comp.lang.fortran,comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: Fortran vs C Message-ID: <1990Dec1.223700.11819@zoo.toronto.edu> Organization: U of Toronto Zoology References: <219@validgh.com> Date: Sat, 1 Dec 90 22:37:00 GMT In article <219@validgh.com> dgh@validgh.com (David G. Hough on validgh) writes: >There have been recent statements that functions like sqrt() are >equivalent in Fortran and C. This is incorrect. > >In C, sqrt() is simply a function invocation. It has no known >semantics unless #include has been seen, in which case >ANSI-C knows that it is a double-precision function of a double-precision >argument... Unfortunately, this too is incorrect. In the absence of #include , "sqrt" remains reserved for system use as an external name, and all bets are off if a program uses it for that purpose itself. (It can, however, be used as an internal-only name, e.g. a static function.) In the presence of #include , it is *not* known to be a double-precision function of a double-precision argument; that is merely one of several possibilities. What is known is that you can call it as if it were one. It may well be a macro whose internals invoke compiler-specific magic, rather than a function invocation of any kind. >Thanks to the default conversions, you can use sqrt on float >arguments with correct results, but they may take twice as long to compute >as necessary if you really meant sqrtf(). There is no programming language that can remove the programmer's ultimate responsibility for efficient code. >sqrt() won't work on long double arguments unless long double == double. However, sqrtl() is reserved for future use for this purpose, and people supplying a useful `long double' type would presumably supply one. >In Fortran, sqrt() is a generic intrinsic function, really an operator like +. I don't recall this in the existing Fortran language (although I have not used Fortran 77 very much and might have missed it). If we're talking about future languages, like Fortran 20xx (called Fortran 9x by some optimists), the folks over in comp.lang.c++ can fill you in on a descendant of C, already in widespread use and in the works for standardization, which permits such things. >As mentioned by others, ANSI-C defines exception handling for the sqrt()... Now, *this* is a real issue, and one I'd forgotten about. -- "The average pointer, statistically, |Henry Spencer at U of Toronto Zoology points somewhere in X." -Hugh Redelmeier| henry@zoo.toronto.edu utzoo!henry Brought to you by Super Global Mega Corp .com