noren@dinl.uucp (Charles Noren) (05/31/90)
In article <1990May30.212533.8105@msuinfo.cl.msu.edu> scholten@cpsvax.cps.msu.edu (David Scholten cps) writes: >What are the benefits of using C versus Fortran? I used Fortran a long time ago (Fortran IV, before Fortran 77), so some of these comments may not apply in respect to Fortran 77. Here is the start of a list of advantages of C over Fortran and Fortran over C: C Advantage list: 1. Data Structures (Fortran IV didn't have them). 2. Cleaner code structures. Rarely do you need labels (as you do in Fortran DO loops, computed goto's, etc.). You do need lables in C case statements. 3. Data Pointers. Even before I used C, there were times I needed to point to areas in memory (with a defined structure). This was faked at various times by using an assembly language function or using a vendor supplied pointer function. Never as clean as C pointers. 4. Ability to have variable argument lists. 5. Ability to do recursive function calls. 6. Macros. 7. Function pointers. One time on a project we needed to implement a function table for a Finite State Machine (for a protocol processor written in Fortran IV -- arghhh!). It was done with integer values in the table fed into a computed goto (yuk!!). In C, you put the function pointers right into the table and call them. 8. Free form entry of code for C vs. the reserved columns for Fortran (at least Fortran IV). This allows nicer indentation style to make the code easier for the human to read. C Disadvantage list: 1. Pointers. This will take pure Fortran hackers a little time to get used to. Pointers are pervasive in C. 2. Perhaps a little less mature library for math stuff. -- Chuck Noren NET: ncar!dinl!noren US-MAIL: Martin Marietta I&CS, MS XL8058, P.O. Box 1260, Denver, CO 80201-1260 Phone: (303) 971-7930
math1i7@jetson.uh.edu (06/04/90)
In article <1990May30.212533.8105@msuinfo.cl.msu.edu>, scholten@cpsvax.cps.msu.edu (David Scholten cps) writes: > I thought I read in EE Times or EDN that C is being accepted > as an official DOD language. Is this true? If not, what is the Don't know for sure, but I had always heard that Ada was the new official Department of Defense language. Gordon Tillman
noren@dinl.uucp (Charles Noren) (06/05/90)
I wrote a *start* of a list of C advantages and disadvantages in response to the question: In article <1990May30.212533.8105@msuinfo.cl.msu.edu> scholten@cpsvax.cps.msu.edu (David Scholten cps) writes: >What are the benefits of using C versus Fortran? A couple of people responded to me by e-mail noting that I forgot about some disadvantages of C to Fortran (forgetting was a generous statement, I didn't know about some of the stuff, particularly aliasing). So here is a revised edition of my list, certainly not complete, with additions and comments welcome. Thanks to Andrew Mullhaupt (mailrus!uunet!Morgan.COM!amull) and from a person from Microsoft (whose name I could not locate in the mail header). (Caveat: I used Fortran a long time ago - Fortran IV in fact. Some of these comments may not apply to later additions of Fortran such as Fortran 77). C Advantage list: 1. Data Structures (Fortran IV didn't have them). 2. Cleaner code structures. Rarely do you need labels (as you do in Fortran DO loops, computed goto's, etc.). You do need lables in C case statements. 3. Data Pointers. Reduces need to copy data which helps make code faster, allows for reentrant/recursive code, and the declaration of structures that can be "overlaid" on memory (useful, for instance, in memory-mapped I/O). 4. Ability to have variable argument lists. 5. Ability to do recursive function calls. 6. Macros. 7. Function pointers. Pointers to functions can be placed in a table and executed "directly" from the table. 8. Free form entry of code for C vs. the reserved columns for Fortran (at least Fortran IV). This allows nicer indentation style to make the code easier for the human to read. C Disadvantage list: 1. Pointers. This will take pure Fortran hackers a little time to get used to. Pointers are pervasive in C. 2. Perhaps a little less mature math library. 3. Fortran compilers have been around longer and are generally better at optimization than C compilers. 4. The Fortran language is designed so that compilers can make useful assumptions for code optimization, which cannot be made for C compilers. Two examples: a. Aliasing is not permitted in Fortran. For instance, if you declare two array arguments in a Fortran subroutine, those arguments cannot be the same array. This permits the subroutine to be compiled with very fast vector instructions (on machines that support vectorization such as Crays). b. The C for statement does not have a well defined "control variable" and thus cannot be automatically vectorized. 5. Array subscripts in C must start with zero, which for some is counter intuitive (of course the C programmer might ask what is so intuitive about starting with 1 ;-)). One person mentioned this can cause optimization problems by defeating alias optimizations in C. 6. C does not permit multidimensional array parameters of different sizes. -- Chuck Noren NET: ncar!dinl!noren US-MAIL: Martin Marietta I&CS, MS XL8058, P.O. Box 1260, Denver, CO 80201-1260 Phone: (303) 971-7930
brnstnd@stealth.acf.nyu.edu (06/06/90)
In article <1631@dinl.mmc.UUCP> noren@dinl.UUCP (Charles Noren) writes: > C Advantage list: > 3. Data Pointers. Reduces need to copy data which helps > make code faster, allows for reentrant/recursive code, > and the declaration of structures that can be "overlaid" > on memory (useful, for instance, in memory-mapped I/O). It's the stack, not the existence of pointers, that allows recursive calls. > C Disadvantage list: > 4. The Fortran language is designed so that compilers > can make useful assumptions for code optimization, > which cannot be made for C compilers. Two examples: > a. Aliasing is not permitted in Fortran. As has been well hashed out in comp.lang.misc, a slightly intelligent compiler can get around this ``disadvantage'' of C, even within the compile-link model. I don't know of any compilers that do so. > b. The C for statement does not have a well defined > "control variable" and thus cannot be automatically > vectorized. The Convex compiler automatically vectorizes loops; I don't know about the Cray UNICOS compiler. > 5. Array subscripts in C must start with zero, which for > some is counter intuitive But with pointers, or even with simple macros, you can trivially get around this ``restriction.'' After #define b (&a[0] + 3), b can be used as an array of the same size as a, starting from -3. (Hmmm: is it guaranteed by ANSI that &a[0] - 1 + 1 equals a?) ---Dan
volpe@underdog.crd.ge.com (Christopher R Volpe) (06/06/90)
In article <17598:Jun611:32:2890@stealth.acf.nyu.edu> brnstnd@stealth.acf.nyu.edu (Dan Bernstein) writes: >In article <1631@dinl.mmc.UUCP> noren@dinl.UUCP (Charles Noren) writes: >> C Advantage list: >> 5. Array subscripts in C must start with zero, which for >> some is counter intuitive > >But with pointers, or even with simple macros, you can trivially get >around this ``restriction.'' After #define b (&a[0] + 3), b can be used >as an array of the same size as a, starting from -3. (Hmmm: is it >guaranteed by ANSI that &a[0] - 1 + 1 equals a?) > >---Dan No, that's not guaranteed. &a[0]-1 is outside the bounds of the array, which is undefined, except when it's one object beyond the end of the array. However, that doesn't apply to your example in this case: "b[-3]" is well defined and equal to "a" because the expression becomes (&a[0]+3)[-3] , and the "+3" is done before the "-3" so you don't have to worry about going before the first element. Of course, if a has 2 elements, &a[0]+3 is overstepping the high end. (a[0] and a[1] are objects, a[2] is a legal reference to the first element beyond the high end, and a[3] is illegal. BTW, why are we saying "&a[0]" instead of "a"???) --Chris (volpecr@crd.ge.com)
brnstnd@stealth.acf.nyu.edu (06/06/90)
In article <8237@crdgw1.crd.ge.com> volpe@underdog.crd.ge.com (Christopher R Volpe) writes: > In article <17598:Jun611:32:2890@stealth.acf.nyu.edu> brnstnd@stealth.acf.nyu.edu (Dan Bernstein) writes: > >In article <1631@dinl.mmc.UUCP> noren@dinl.UUCP (Charles Noren) writes: > >> 5. Array subscripts in C must start with zero, which for > >> some is counter intuitive > >But with pointers, or even with simple macros, you can trivially get > >around this ``restriction.'' After #define b (&a[0] + 3), b can be used > >as an array of the same size as a, starting from -3. (Hmmm: is it > >guaranteed by ANSI that &a[0] - 1 + 1 equals a?) > No, that's not guaranteed. &a[0]-1 is outside the bounds of the > array, which is undefined, except when it's one object beyond the > end of the array. In that case, numbering an array from 1 or any other positive number by the above method is not ANSI compliant, though it will work on any real machine. Numbering it from x through y, where x is negative and y is at least -1, is both portable and fully compliant. If you don't care about such syntactic purity then #define b(i) (a[i - x]) does the job in all cases. > However, that doesn't apply to your example > in this case: "b[-3]" is well defined and equal to "a" I know, but I was worrying about the opposite case. > BTW, why are we saying "&a[0]" instead of "a"???) To help the Fortran and Pascal types at whom this thread is directed. ---Dan
darcy@druid.uucp (D'Arcy J.M. Cain) (06/09/90)
In article <6319.26691746@jetson.uh.edu> math1i7@jetson.uh.edu writes: >In article <1990May30.212533.8105@msuinfo.cl.msu.edu>, >scholten@cpsvax.cps.msu.edu (David Scholten cps) writes: >> I thought I read in EE Times or EDN that C is being accepted >> as an official DOD language. Is this true? If not, what is the >Don't know for sure, but I had always heard that Ada was the new official >Department of Defense language. However I believe that C is the language of choice in the Denizens of Doom. :-) DoD #0082 -- D'Arcy J.M. Cain (darcy@druid) | Government: D'Arcy Cain Consulting | Organized crime with an attitude West Hill, Ontario, Canada | (416) 281-6094 |