CS 553

Fortran 77 versus C


This page was last updated: November 29, 2005


ItemFortran 77C
Usual data typesINTEGER, REAL, CHARACTERint, float, char
Double precisionDOUBLE PRECISIONdouble
Pointer variablesnoneint *, float *, char *, double *
Structuresnonestruct { ... } ;
CaseSingle case onlyUpper and lower case sensitive
DeclarationsInteger = I-NAll variables must be declared
Type castingF = FLOAT( I )f = (float) i ;
Type castingI = IFIX( F )i = (int) f ;
Array declarationsINTEGER I(10)int i[10] ;
Array indicesStart at 1 (eg, 1-10)Start at 0 (eg, 0-9)
GlobalsCOMMON statementsDeclared outside of all routines
Main programComes first in programLooks like a subroutine called main( argc, argv )
ContinuationCharacter in column 6Statement terminated with ;
Arithmetic* / + -* / + -
ExponentiationA ** Bpow( a, b ) ;
Pointer arithmeticnone&, * unary operators
IF relations.EQ. , .NE. , .GT. , .GE == , != , > , >=
IF relations.LT. , .LE. , .AND. , .OR < , <= , && , ||
Main loopingDO 100 I = 1, 10for( i = 1; i <= 10; i = i + 1 )
Continue next loopGOTO 100continue ;
Break out of loopGOTO 200break ;
Other loopingnonewhile and do...while
Blocks of statementsBounded by labels or then-endifBounded by { }
OutputWRITE, FORMAT, ...printf(...), fprintf(...)
InputREAD, FORMAT, ...scanf(...), fscanf(...)
Pre-initializationDATA statementGlobal assignment
Statement labelsNumbersNames
GOTOsGO TO 1000goto proceed ;
Use of GOTOsNecessary oftenRarely necessary
ConstantsPARAMETER#define
Variables passedBy addressBy copying the value
Dynamic Mem AllocNomalloc(...), realloc(...)
SwitchingGOTO ( ... ), Iswitch(i) { ... }
FunctionsIABS(I), ABS(F)abs(i), fabs(f)
FunctionsSQRT(F)sqrt(f)
FunctionsSIN(F), COS(F)sin(f), cos(f)
FunctionsATAN(F), ATAN2(F1,F2)atan(f), atan2(f1,f2)
FunctionsEXP(F), ALOG(F), ALOG10(F)exp(f), log(f), log10(f)