Should I convert FORTRAN code to C?

Jim Giles jlg at beta.lanl.gov
Sat Jun 18 04:49:06 AEST 1988


In article <224 at raunvis.UUCP>, kjartan at raunvis.UUCP (Kjartan Pierre Emilsson Jardedlisfraedi) writes:
>   Now here there seems to be a little misunderstanding.  I have never
> understood why Fortran users keep saying that array indexing is awkward
> in C.
> [...]

Awkward isn't the problem.  I don't like the double bracket notation,
but anyone can write a macro to turn ARRAY(i,j,k) into array[i][j][k].
The Problem is that 2-d arrays are not optimizable because they are
immediately turned into pointer-to-pointer-to-data type of constructs.

>   If the array had been initialized with Create2DArray() then indexing
> would be just as normal,i.e:
> 
> 		DoSomething(array,m,n)
> 		double **array;
> 		int m,n;
> 		{
> 		...
> 		array[ i+k ][ j-i ]= 1.0;
> 		...
> 		}

If your use of array here is in a loop (that might otherwise be vector-
izable), the C compiler can't vectorize it because a pointer-to-pointer
'may' contain a vector dependency - the compiler doesn't know it's a
2-d array!  (If you don't have a vector machine, the problem still exists,
you can't unroll the loop for a pipelined archetecture because of the
same possible dependency.)  This problem is the reason that so much
discussion on this news group has recently been about 'noalias' in C (not
exactly an appropriate topic for comp.lang.fortran, but relevent to this
particular issue anyway).

> [...]
> 	       ii) You can define your own data structures, which can be any
> 		   combination of system defined structures and user defined
> 		   structures, array of structures, self-referential
>                  structures and so on. [...]

This capability is NOT an adequate replacement for the complex data type.
Complex is more than just a pair of reals, there are several operations
defined on complex (like plus) which should work naturally.  No use of
C programming constructs can do this:

      COMPLEX CVAR
      REAL RVAR
      INTEGER IVAR
      ...
      CVAR=(CVAR+RVAR)*IVAR
      ...
The operations (including the mixed-mode type conversions) are all done
IN-LINE and efficiently.  C provides no way to even do this calculation
without function calls.

>   This is not meant as an artillery in the Language Wars, but rather as an
> explanation and maybe a clarification for those who haven't had any special
> experience with C ,and still think that indexing doesn't exist in C and that
> C is bad because it doesn't have the complex data type!

Clarifications which contain false or misleading information don't
clarify anything.  In fact, such 'clarifications' DO add to the
Language Wars in very unproductive ways.

J. Giles
Los Alamos



More information about the Comp.lang.c mailing list