12.07.2015 Views

PGI User's Guide

PGI User's Guide

PGI User's Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Array Indices! Fortran function returns a characterCHARACTER*(*) FUNCTION CHF(C1,I)CHARACTER*(*) C1INTEGER IEND/* C declaration of Fortran function */extern void chf_();char tmp[10];char c1[9];int i;chf_(tmp, 10, c1, &i, 9);Example 12.1. Character Return ParametersIf the Fortran function is declared to return a character value of constant length, for example CHARACTER*4FUNCTION CHF(), the second extra parameter representing the length must still be supplied, but is notused.NoteThe value of the character function is not automatically NULL-terminated.Complex Return ValuesWhen a Fortran function returns a complex value, an argument needs to be added at the beginning of the C/C++ calling function’s argument list; this argument is the address of the complex return value. Example 12.2,“COMPLEX Return Values” illustrates the extra parameter, cplx, supplied by the caller.156COMPLEX FUNCTION CF(C, I)INTEGER I. . .ENDextern void cf_();typedef struct {float real, imag;} cplx;cplx c1;int i;cf_(&c1, &i);Array IndicesExample 12.2. COMPLEX Return ValuesC/C++ arrays and Fortran arrays use different default initial array index values. By default, C/C++ arrays startat 0 and Fortran arrays start at 1. If you adjust your array comparisons so that a Fortran second element iscompared to a C/C++ first element, and adjust similarly for other elements, you should not have problemsworking with this difference. If this is not satisfactory, you can declare your Fortran arrays to start at zero.Another difference between Fortran and C/C++ arrays is the storage method used. Fortran uses columnmajororder and C/C++ uses row-major order. For one-dimensional arrays, this poses no problems. For twodimensionalarrays, where there are an equal number of rows and columns, row and column indexes cansimply be reversed. For arrays other than single dimensional arrays, and square two-dimensional arrays, interlanguagefunction mixing is not recommended.

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

Saved successfully!

Ooh no, something went wrong!