Problem areas


C and Fortran 77 are similar algorithmic languages, with only a few basic conceptual differences.  A lot of the algorithmic material in a Fortran can be converted over to C in a fairly automatic way.   Here are some areas that will cause problems, and what I did about them.

Culture shocks

C is case sensitive.  This is why Unix is case sensitive.

All arithmetic and math functions are double precision.  Using single precision may actually slow things down because of the frequent casts between single and double that result.  Modern CPUs are very good at double precision math.  Double precision will take more time than single if the memory access time is slow, since there are twice as many words to recover.

There is no exponentiation like ** in Fortran.  Instead you call a library function, pow(a,b).  People who have trouble dealing with this need to get a life.

There are reserved keywords in C.  These cannot be used for variable names.   There are even more reserved keywords in C++, and the compiler manufacturer can make more too.

The array concepts in C are fundamentally different from Fortran.  A 2D array is actually an array of pointers to arrays.

There is no bounds checking on arrays in C.  This is a major problem.  If is necessary to add asserts throughout the code to ensure safe array bounds.

C is call by value instead of call by reference.  Fortran has always had call by reference, and C++ has introduced it.  This may be one area where you might want to go straight to C++.

Problem areas

The code must be fairly close to ANSI FORTRAN 77 for automatic conversion to take place. The f2c utility is freely available.   I know of no converters for F90 or F95.

Structures are one of the most useful data forms in C but have no counterpart in F77.

Common blocks and block datas do not exist in C.  Commons will need to be changed over to global variables, and to do this all variables must have unique names.  Block datas can become routines that execute and set variables to a value, or set to an initial value when the variable is defined.

C arrays start with zero, the lower limit cannot be changed, and the order of the indices are switched compared to Fortran.  These issues can be handled by a translator but might be confusing when the code is maintained.

Global variables are defined (given a piece of memory) in a single place, and then are declared in other places that need to use it.  This concept does not exist in Fortran - the definition is automatically done when a variable is declared.

IO is stream oriented in C, and line oriented in Fortran.  This is a major problem - an automatically translated Fortran environment will simulate the line IO of Fortran.   It will take a great deal of work to convert this to the C way of doing things.