Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!sco!seanf From: seanf@sco.COM (Sean Fagan) Newsgroups: comp.lang.misc Subject: Re: NOT Educating FORTRAN programmers to use C Message-ID: <4540@scolex.sco.COM> Date: 22 Jan 90 22:46:20 GMT References: <12950@cbnewsc.ATT.COM> <14199@lambda.UUCP> Reply-To: seanf@sco.COM (Sean Fagan) Organization: The Santa Cruz Operation, Inc. Lines: 54 In article <14199@lambda.UUCP> jlg@lambda.UUCP (Jim Giles) writes: >Fortran allows intrinsic functions to be optimized, C hasn't any intrinsics >(I know, the new standard permits such - show me an available implementation >before you mention it again). Microsoft C 5.0 and later, and MetaWare HighC, don't knot what versions, but at least after 1.5x. MSC has a bunch of str* and most of the mem* inlined, and HighC has oodles and oodles of them (cos and sin, for example, if called with the same argument, it will translate into a single fsincos instruction [if you're using a '387]). These are available *now*. >On the other hand, C can optimize procedure calls (or even 'inline' them) >provided that the procedure and the call are in the same scope (file). >I don't know of any C implementation that actually does this, but it _is_ >permitted by the existing (de facto) language specification. gcc does. MetaWare's latest compiler ("globally optimizing," but I don't know what they mean by that) might, I'm not sure. >Fortran (pascal, Modula2, ADA, ...) lets me do so >with parenthesis - C forces me to introduce temporary variables and >_hope_ that the optimizer doesn't actually do a store/load. Read your standards. ANSI-C (a reality, now) has requirements for order-of-evaluation, much to my chagrin. Since most companies have been developing their compilers in parallel to X3J11, there are quite a few compilers available now to do this (MSC has it, I think, and I'm almost positive HighC does). >This is a particularly bad example for you to use. The optimization >that you want the compiler to do without is called "common subexpression >elimination". It is important that your compiler know how to do this >optimization even if you do have a '+=' operator. I wouldn't ever buy >a compiler which didn't have this capability. A compiler without this >capability is somewhat behind the state-of-the-art anyway (by about 30 >years). x[i] = x[i] + foo(); vs. x[i] += foo(); where one or more of x and i are global. Oops. If your FORTRAN copmiler optimizes that away, you quite probably, have some problems. Some of Jim's points have merit. However, he does not really seem to know what's available in C compilers today, nor what the C standard (no longer a draft!) says, which kinda hurts his arguments. -- Sean Eric Fagan | "Time has little to do with infinity and jelly donuts." seanf@sco.COM | -- Thomas Magnum (Tom Selleck), _Magnum, P.I._ (408) 458-1422 | Any opinions expressed are my own, not my employers'.