From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 110292,45b50f14dadfce5b X-Google-Attributes: gid110292,public X-Google-Thread: 102b75,45b50f14dadfce5b X-Google-Attributes: gid102b75,public X-Google-Thread: 1164f8,45b50f14dadfce5b X-Google-Attributes: gid1164f8,public From: Craig Burley Subject: Re: Final kick at the "Merced Guessing Game" Date: 1997/10/19 Message-ID: X-Deja-AN: 282399621 References: <61g30t$o2n@news-rocq.inria.fr> <623ek6$ef5$1@news.iastate.edu> <3447C681.167E@lanl.gov> Organization: Cygnus Support Newsgroups: comp.sys.intel,comp.arch,comp.sys.dec William Clodius writes: > Craig Burley wrote: > > > > Care to explain what *low-level* > > constructs C is offering that Fortran doesn't offer, aside from > > pointers? > > Guaranteed ability to pass some arguments by value, or have a well > defined result in the presence of aliasing (whether or not the initial > programmer or the user of the code knows what that well defined result > is). C has an IMO important linguistic/syntactic advantage in that the programmer (and thus the compiler) *knows* that "foo (a);" will not modify `a', indeed. Fortran's version of this is "CALL FOO((A))", and of course the FOO *subroutine* can be fairly easily determined to not modify its argument. However, in practice, the typical compiler cannot determine that all calls to FOO are done via (A) and/or that FOO itself can take the argument by value, so it must assume pass-by-reference. So, when passing an argument by value as a *mechanism* is faster in an important way, then I think this is an important advantage to C. (Note that I *could* argue that Fortran compilers "could" [and in fact, I've been told some do] determine that pass-by-value would work and thus implement the faster form anyway...but what a super-fancy compiler can *intuit* from code made intentionally obtuse by the failings of a language is *not* the issue here, else, as I've pointed out elsewhere, we might as well say that C and/or the x86 assembly language is "just fine" for achieving maximum speed on *all* future architectures.) BTW, another thing I prefer in C, though it's purely linguistic and has no performance implications, is that function references are syntactically distinct from array references. I don't usually bring this up, because, for some reason I haven't quite grokked yet, Fortran programmers don't seem to experience any problems as a result of this in practice. However, Fortran does offer the ability to do aliasing, when it is important enough to do. Instead of SUBROUTINE BIGMUL(A,B,C,N) REAL A(N),B(N),C(N) DO I=1,N A(I)=B(I)*C(I) END DO END you provide: SUBROUTINE BIGMULA(A,IA,IB,IC,N) REAL A(MAX(IA,IB,IC)+N-1) DO I=0,N-1 A(IA+I)=A(IB+I)*A(IC+I) END DO END This makes it clear to the compiler (and the person reading the code, both the caller and callee, pretty much) that aliasing is designed into the routine. (Strictly speaking, you can't use intrinsics, like MAX(), in an array decl, I believe; but you can either expand it to the appropriate expression, or just use `*'.) > Compared to Fortran 77, not Fortran 90, structures. Not sure this is superior for performance. Guaranteed it is for expressability. I've already said I've seen real gross Fortran code that achieves what amounts to the same thing, performance-wise, as C structures, though I suspect even if people wanted to force the issue and use Fortran, they'd end up with the same problem C imposes on Fortran users by not having multi-dimensional arrays: the compiler would have to be *lots* smarter to figure out how to do some nifty optimizations. On the other hand, C does offer a few ways of being more flexible in how to specify initial values for variables and aggregates. One thing I love about C is its file scoping, for example, which allows several procedures to share static data, which explicitly permits the compiler (and programmer) to make all sorts of usable, practical assumptions about the kinds of things that can be done vis-a-vis the static data. Then again, C offers nothing like "COMMON /X/ A(1000000)", especially when in a BLOCK DATA combined with "DATA A(1)/1./". This *can* have a substantial performance impact, although I suspect that, in practice, most such cases would be mitigated by the fact that the Fortran was "written around" not having dynamic allocation (which C has, of course). (The reason? The Fortran initialization literally says "the first element of A is 1; the rest are uninitialized", while C doesn't allow specifying that portions of variables are uninitialized, or even static/extern ones IIRC, the latter being mostly a linguistic failing except when the aggregate sizes of gratuitously zero-initialized entities is large enough to impact executable size and startup time.) > Unions (but much of that can be kluged using EQUIVALENCE). (Then again > unions themselves are usually kluges in their application.) Yup, I don't see a clear win here, though, personally, I prefer C's unions to Fortran's EQUIVALENCE. > There is also the problem of API's on C implemented systems, name > mangling, the possibility of copy-in/copy-out Fortran argument passing, > i.e., the interlanguage interfacing problem. None of this is strictly a > problem with the Fortran language per se, but does influence its > useability as a runtime library on most current systems. Yup, I mentioned that elsewhere, except the part about copy-in/copy-out passing, which is a practical advantage in favor of Fortran on some systems. -- "Practice random senselessness and act kind of beautiful." James Craig Burley, Software Craftsperson burley@gnu.ai.mit.edu