Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!samsung!munnari.oz.au!bruce!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.misc Subject: Re: C vs. FORTRAN (was C official DOD langauge?) Message-ID: <3169@goanna.cs.rmit.oz.au> Date: 7 Jun 90 00:03:55 GMT References: <1633@dinl.mmc.UUCP> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 67 In article <1633@dinl.mmc.UUCP>, noren@dinl.uucp (Charles Noren) writes: : C Advantages over FORTRAN: : 1. Data Pointer Types. FORTRAN apparently still does not : have a pointer type. Several existing Fortrans have pointers. They're in Fortran-90. : 4. Macros. In most C implementations, macros are expanded : in a separate program from the actual C compiler, known as : the C Pre-Processor (cpp). One person suggested that : FORTRAN code could be run through cpp and thus have macros. : I have not tried this, but it is an interesting idea. I have done it and if you take reasonable care it works fine. Of course, cpp is not the only macro processor around. Even for C itself, it is often a better idea to use something like M4, and M4 is not language-specific. : 5. Dynamic memory allocation. f77 does not have this, but : apparently f9x will have dynamic memory allocation. Existing Fortrans with pointers often do have dynamic memory allocation. Yes, it is in Fortran-90. (See the ALLOCATE statement.) : (Question: It's been so long since I've used : FORTRAN, but how does the EQUIVELANCE statement : affect or not affect aliasing?) If you're using one of the variables in an EQUIVALENCE group, what you get when you use one of the others isn't defined. : b. The C for statement does not have a well defined : "control variable" and thus cannot be automatically : vectorized. Bogus. It is true that there is no _syntactically_ distinguished variable, but all you have to do is watch out for a variable which is incremented by a constant and is tested against an invariant bound. Anything expressible as a Fortran DO statement can be expressed as a C for () statement and can be recognised this way. : However, it would seem that : FORTRAN, with its way specifying a starting index (if it : truly is part of "standard" FORTRAN and not just a vendor : language enhancement) has the advantage here. Yes, arbitrary lower bounds are part of the Fortran-77 standard. : 7. C does not have the COMPLEX data type. C++ has. : 9. Dynamic memory. Due to the use of pointers in C, : dynamic memory is used often in C. How and when to use : dynamic memory (and which are the best dynamic memory : functions) can cause debate with C programmers. With the : use of dynamic memory come subtle bugs (memory leaks) which : can be hard to trace. Don't blame the bugs on "dynamic memory". Blame them on forcing programmers to do their own storage allocation (malloc() and free()). Don't expect Fortran in any version to be better. -- "A 7th class of programs, correct in every way, is believed to exist by a few computer scientists. However, no example could be found to include here."