Pitfalls on porting FORTRAN 90 to C


I am porting a 3000-line Fortran 90 source code to ANSI C in these days, and I would like to mark the pitfalls in this adventure:

  • Use 1-index Don’t try to act professional to use 0-index, that would confuse yourself in a few minutes, use 1-index, we can afford the one element waste.
  • Be careful of for loop FORTRAN support for loop with increment/decrement, while C does not.
  • ABS != abs Surprising? abs in C return integer, not double. I am quite annoyed to find the compiler (gcc-4.1) does not even issue a warning for the implicit conversion. Use fabs instead
  • Prepare your debugger if you have a 300 line function, and messed global variables, taking some time to learn gdbis definitely worthy, – Intel FORTRAN, idb also supports gdb mode.