From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 102b75,45b50f14dadfce5b X-Google-Attributes: gid102b75,public X-Google-Thread: 110292,45b50f14dadfce5b X-Google-Attributes: gid110292,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: #1/1 X-Deja-AN: 282399623 References: Organization: Cygnus Support Newsgroups: comp.sys.intel,comp.arch,comp.sys.dec pmontgom@cwi.nl (Peter L. Montgomery) writes: > In article > Craig Burley writes: > > >I don't see any rebuttal there. Care to explain what *low-level* > >constructs C is offering that Fortran doesn't offer, aside from > >pointers? > > Nobody has been mentioning unsigned arithmetic. > In many implementations of Fortran (and C), signed and unsigned > additions and subtractions behave identically, but C > _guarantees_ what the result will be if it overflows, which > Fortran does not. Good call! I bet this does help low-level stuff. All Fortran lets you do in unsigned is what you can accomplish with intrinsics (say, MIL-STD 1753) or external procedures, which isn't as easily optimized. > C has conditional compilation, which Fortran does not. I'd say the fact that `cpp' is so widely available, and can thus provide conditional compilation for Fortran, mitigates this sufficiently. In practice, tons of Fortran code is either written "just fine" without a preprocessor, or one is used. Though, there are too many different ones. Hard to see how this really benefits low-level coding, however. > Fortran leads C in its large intrinsic function library. > C9X will finally let one write a MAX function which evaluates its > arguments once only and use the INLINE keyword to get good code, > but the user will need to call different functions depending > upon the argument types (cf. labs/abs/fabs in C vs. ABS in Fortran). Hmm. Still not a big win for low-level coding for Fortran, though. I wonder if ?: might be an important, but oft-overlooked, win for low-level coding in C? You can probably *achieve* the same thing in Fortran using intrinsics and such, and certainly via statements, plus Fortran wouldn't "want" to have the sequence-point aspect of it, but I wonder if a generic CASE(N,E1,E2,...,En) intrinsic that returns the value of expression E(N) would have made Fortran better for low-level stuff. I use ?: a lot in my C code, and usually don't care if both choices happen to get evaluated, but sometimes do care that a C compiler might be able to avoid the subexpression entirely (something harder for a Fortran compiler if the statement equivalent, i.e. IF/THEN/ELSE, is used, since it means figuring out temporary variables' lifetimes, etc.). Okay, so now I think the list of features "classic" K&R C offers that "classic" FORTRAN 77 doesn't and that can make writing fairly clean, *fast* low-level code easier than in FORTRAN consists of: - Unsigned integer arithmetic - Pass by value - Structs - ?: (*maybe*) I'll try to keep this list in mind next time I'm tempted to pick on C again (or, really, rebut the frequent "Fortran is useless" rants on USENET ;-). -- "Practice random senselessness and act kind of beautiful." James Craig Burley, Software Craftsperson burley@gnu.ai.mit.edu