Category Archives: Computers and Internet

The Difference between C/C++ and Fortran 90

 
to be continue later
 
=====================================
The Difference between C/C++ and Fortran 90
=====================================
———————————————————————-
Keywords:
Difference, Comparison, C, Fortran
———————————————————————–
Abstract
This article is to give some hints for people who have some basic knowledge of C/C++.
Special attention is deserved in following aspects, if some one hope to obtain this new language quickly.
(1) Efficiency: Fortran is more efficient for math computation. Complex number supported.
(2) parameter transfer: All parameter is transfer by reference,  BE CAREFUL!!!
i.e. once the value of variables changed in function or subroutine,  value of variables change outside, too.
In C programming, ONLY a copy is transferred to function for all value type(int, double) and struct, which are not refered by
pointer(reference & in C++). Yet, array and all pointer variables are transfer by reference. the name of array, which is a pointer
to the initial addr. of memory.
[3] character array: It is not ended by ” in Fortran. Blanks(space bar on keyboard) is filled?
(4) Index and memory allocation for multiple dimension array(>=2): Fortran is column-first allocation in continuous memory, but
if we use only index, we need not worry about how the compiler allocate each element. In Contrary, the modifier of ‘const’ can
protect variable(data type and p) from undesired modification. The compiler will give a double-check after your first check.
The index of Fortran is flexible but complicate. The Lower bound is 1, not 0 in C. In fact, you can define the lower bound by
yourself.
(5) OOP: F90 provides some object oriented features, TYPE( corresponding to struct, class in C), INTERFACE, MODULE. TYPE
should be useful.
[6] Array manipulation: F90 provides some parallel support. it is preeminent advantage of Fortran.
[7] Overview of the difference between F77 and F90
implicit naming rule and fixing style of source code in F77
======================================
1. basic intrinsic functions
if you know those func. you can write your first Fortran program
(1)write, read, print:
(2)format leter: similar with C format,
(3)intrinsic math functions names, whose names are almost same with double precision in C. are same for different presicion
2. One sentence of difference
(1)Fortran does not distinguish captalized and uncaptalized letters
(2) size_of(), lenth_of()
(3) const string in C ends with ”, while in Fortran
3. ‘const’ contract, or parameter protection
int b;
int c=0;
int* const  p1 = &b; // Error if:  p1 = &b;
const int* p2=&c; // Error if: *p2 = 3;
int a[3] = {1,2,3};
void func(const int a[] )
{
// Error if: a[0] = 4;
}
 
F90 provide some protection from : PARAMETER, equals to ‘const’ in C;
INTENT(in), which means you can not modified the value inside the function.
 
As mentioned, if you wanted to modified the value by call a function, you need transfer reference/pointer.
The concept of "&"( called ‘reference’) exists only in C++. While "&" is called fetch the memery address of the variable,which
happens when you assign a pointer variable.
 
Reference:
Appendix:
I. Resource of Fortran Compiler
http://www.personal.psu.edu/faculty/h/d/hdk/fortran.html