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.

Order of Arguments in Argument List<br />

The argument list is constructed in the following order. Items in the same bullet<br />

appear in the same order as in the procedure declaration, whether or not argument<br />

keywords are used in the call.<br />

v All addresses or values (or both) of actual arguments 4<br />

v “Present” indicators <strong>for</strong> optional arguments that are passed by value<br />

v Length arguments <strong>for</strong> strings 4<br />

Linkage Convention <strong>for</strong> Function Calls<br />

A routine has two symbols associated with it: a function descriptor (name) and an<br />

entry point (.name). When a call is made to a routine, the program branches to the<br />

entry point directly. Excluding the loading of parameters (if any) in the proper<br />

registers, compilers expand calls to functions to the following two-instruction<br />

sequence:<br />

BL .foo # Branch to foo<br />

ORI R0,R0,0x0000<br />

# Special NOP<br />

The linker does one of two things when it encounters a BL instruction:<br />

1. If foo is imported (not in the same object module), the linker changes the BL to<br />

.foo to a BL to .glink (global linkage routine) of foo and inserts the .glink<br />

into the object module. Also, if a NOP instruction (ORI R0,R0,0x0000)<br />

immediately follows the BL instruction, the linker replaces the NOP instruction<br />

with the LOAD instruction L R2, 20(R1).<br />

2. If foo is bound in the same object module as its caller and a LOAD instruction<br />

L R2,20(R1) <strong>for</strong> 32-bit and L R2,40(R1) <strong>for</strong> 64-bit, or ORI R0,R0,0 immediately<br />

follows the BL instruction, the linker replaces the LOAD instruction with a<br />

NOP (ORI R0,R0,0).<br />

Note: For any export, the linker inserts the procedure’s descriptor into the object<br />

module.<br />

Pointers to Functions<br />

A function pointer is a data type whose values range over procedure names.<br />

Variables of this type appear in several programming languages, such as C and<br />

<strong>Fortran</strong>. In <strong>Fortran</strong>, a dummy argument that appears in an EXTERNAL statement<br />

is a function pointer. <strong>Fortran</strong> provides support <strong>for</strong> the use of function pointers in<br />

contexts such as the target of a call statement or an actual argument of such a<br />

statement.<br />

A function pointer is a fullword quantity that is the address of a function<br />

descriptor. The function descriptor is a 3-word object. The first word contains the<br />

address of the entry point of the procedure. The second has the address of the<br />

TOC of the object module in which the procedure is bound. The third is the<br />

environment pointer <strong>for</strong> some non-<strong>Fortran</strong> languages. There is only one function<br />

descriptor per entry point. It is bound into the same object module as the function<br />

it identifies if the function is external. The descriptor has an external name, which<br />

is the same as the function name but with a different storage class that uniquely<br />

identifies it. This descriptor name is used in all import or export operations.<br />

4. There may be other items in this list during <strong>Fortran</strong>-<strong>Fortran</strong> calls. However, they will not be visible to non-<strong>Fortran</strong> procedures<br />

that follow the calling rules in this section.<br />

Interlanguage Calls 365

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

Saved successfully!

Ooh no, something went wrong!