12.07.2015 Views

LF95 Linux User's Guide - Lahey Computer Systems

LF95 Linux User's Guide - Lahey Computer Systems

LF95 Linux User's Guide - Lahey Computer Systems

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Returning Function Values to Fortranfunction cfun()character(len=*) :: cfuncfun = ‘1234567890’end function cfunis invoked from C as follows:void cfun_(char *str1, int strlen);MAIN__(){char mystr[10];cfun_(mystr,10);}The preceding example may be a bit confusing, since it runs counter to the intuitive conceptof a function returning a value. For further explanation, see “Passing Character Data” onpage 60.Returning Function Values to FortranC functions are also called by Fortran as functions returning a value. By default, all argumentsare passed to C by reference. Arguments may also be passed to C by value usingLF64’s VAL() intrinsic. It is not possible to return character strings or structures from C.Fortran calls “void” C functions in the same manner that it calls Fortran subroutines. Thisconcept is illustrated in the section below, “Passing and Receiving Arguments” on page 58.Table 9: Declaring Fortran Result Types for C Function TypesC Function Type Fortran Result Type Examplevoid not applicable call my_c_func()signed char INTEGER(1) result = my_c_func()short int INTEGER(2) result = my_c_func()long intINTEGER(4)LOGICAL(4)result = my_c_func()long long int INTEGER(8) result = my_c_func()float REAL(4) result = my_c_func()double REAL(8) result = my_c_func()long double REAL(16) result = my_c_func()char cannot be accepted not applicablestructure cannot be accepted not applicable<strong>Lahey</strong>/Fujitsu <strong>Linux</strong>64 Fortran User’s <strong>Guide</strong> 57

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!