24.05.2014 Views

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

SHOW MORE
SHOW LESS

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

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

Explicit Interface <strong>for</strong> %VAL and %REF<br />

You can specify an explicit interface <strong>for</strong> non-<strong>Fortran</strong> procedures to avoid coding<br />

calls to %VAL and %REF in each argument list, as follows:<br />

INTERFACE<br />

FUNCTION C_FUNC(%VAL(A),%VAL(B)) ! Now you can code "c_func(a,b)"<br />

INTEGER A,B<br />

! instead of<br />

END FUNCTION C_FUNC<br />

! "c_func(%val(a),%val(b))".<br />

END INTERFACE<br />

Returning Values from <strong>Fortran</strong> Functions<br />

<strong>XL</strong> <strong>Fortran</strong> does not support calling certain types of <strong>Fortran</strong> functions from<br />

non-<strong>Fortran</strong> procedures. If a <strong>Fortran</strong> function returns a pointer, array, or character<br />

of nonconstant length, do not call it from outside <strong>Fortran</strong>.<br />

You can call such a function indirectly:<br />

SUBROUTINE MAT2(A,B,C) ! You can call this subroutine from C, and the<br />

! result is stored in C.<br />

INTEGER, DIMENSION(10,10) :: A,B,C<br />

C = ARRAY_FUNC(A,B) ! But you could not call ARRAY_FUNC directly.<br />

END<br />

Arguments with the OPTIONAL Attribute<br />

When you pass an optional argument by reference, the address in the argument list<br />

is zero if the argument is not present.<br />

When you pass an optional argument by value, the value is zero if the argument is<br />

not present. The compiler uses an extra register argument to differentiate that<br />

value from a regular zero value. If the register has the value 1, the optional<br />

argument is present; if it has the value 0, the optional argument is not present.<br />

Related In<strong>for</strong>mation: See “Order of Arguments in Argument List” on page 365.<br />

Arguments with the INTENT Attribute<br />

Currently, declaring arguments with the INTENT attribute does not change the<br />

linkage convention <strong>for</strong> a procedure. However, because this part of the convention<br />

is subject to change in the future, we recommend not calling from non-<strong>Fortran</strong><br />

procedures into <strong>Fortran</strong> procedures that have INTENT(IN) arguments.<br />

Type Encoding and Checking<br />

Run-time errors are hard to find, and many of them are caused by mismatched<br />

procedure interfaces or conflicting data definitions. There<strong>for</strong>e, it is a good idea to<br />

find as many of these problems as possible at compile or link time. To store type<br />

in<strong>for</strong>mation in the object file so that the linker can detect mismatches, use the<br />

-qextchk compiler option.<br />

Assembler-Level Subroutine Linkage Conventions<br />

The subroutine linkage convention specifies the machine state at subroutine entry<br />

and exit, allowing routines that are compiled separately in the same or different<br />

languages to be linked. The in<strong>for</strong>mation on subroutine linkage and system calls in<br />

the <strong>AIX</strong> Commands Reference is the base reference on this topic. You should consult<br />

it <strong>for</strong> full details. This section summarizes the in<strong>for</strong>mation needed to write<br />

mixed-language <strong>Fortran</strong> and assembler programs or to debug at the assembler<br />

level, where you need to be concerned with these kinds of low-level details.<br />

Interlanguage Calls 355

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

Saved successfully!

Ooh no, something went wrong!