FTN77 User Defined Functions
FTN77 User Defined Functions
uk
The return type is required only if the function identifiers type is not implicitly defined3. But it is good practice to state the return type in all function calls. In the body of the function the arguments are declared. Usually at the end of the coding for the function, the return value is assigned to the function identifier. When the function is called, the types of the function identifier must be declared if it is not implicitly defined. The types of the arguments must also match those in the function declaration. A typical function for calculating the area of a rectangle is defined here, and a call to the function from a main program and the output is shown.
C Functions demo PROGRAM AREADEMO REAL*4 ALENGTH, AWIDTH ALENGTH=3.0 AWIDTH=2.0 WRITE(*,*) 'AREA= ',AREA(ALENGTH,AWIDTH) END C Function RECAREA returns the area of a rectangle C given its length and width REAL*4 FUNCTION AREA(LENGTH,WIDTH) REAL*4 LENGTH,WIDTH AREA=LENGTH*WIDTH END