Developer Guide and Reference

ID 767251
Date 10/31/2024
Public
Document Table of Contents

CFI_setpointer

C function prototype: Updates a C descriptor for a Fortran pointer to be associated with the whole of a given object or to be disassociated.

int CFI_setpointer(CFI_cdesc_t *result, CFI_cdesc_t *source,
                   const CFI_index_t lower_bounds[]);

Formal Parameters:

result

The address of a C descriptor whose attribute is CFI_attribute_pointer. It is updated using information from the source and lower_bounds arguments.

source

A null pointer or the address of a C descriptor for a nonallocatable nonpointer data object, an allocated allocatable object, or a data pointer object. If source is not a null pointer, the corresponding values of the elem_len, rank, and type members must be the same in the C descriptors with the addresses source and result. The source can be the same as result.

lower_bounds

If source is not a null pointer and source->rank is nonzero, lower_bounds must be a null pointer or the address of an array with at least source->rank elements; otherwise, lower_bounds is ignored.

Description

Successful execution of CFI_setpointer updates the C descriptor with the address result as follows:

  • If source is a null pointer or the address of a C descriptor for a disassociated pointer, the updated C descriptor describes a disassociated pointer.

  • Otherwise, the C descriptor with the address result becomes a C descriptor for the object described by the C descriptor with the address source, except that if source -> rank is nonzero and lower_bounds is not a null pointer, the lower bounds are replaced by the values of the first source -> rank elements of the lower_bounds array.

    If source -> rank is nonzero and lower_bounds is a null pointer, the lower bounds in result are assigned the values of the lower bounds in source. If the C descriptor with address result describes a deferred-length character pointer, the value of its elem_len is set to source -> elem_len.

The C descriptor with address result is not updated if an error occurs. If source is not a null pointer and no error occurs, result -> base_addr is assigned the value of source -> base_addr.

Result Value

The result is an error indicator. A nonzero result indicates an error occurred; a zero result indicates successful execution.

Example

If ptr is already the address of a C descriptor for an array pointer of rank 1, the following code updates it to be a C descriptor for a pointer to the same array with lower bound 0:

CFI_index_t lower_bounds[1];
int ind;
lower_bounds[0] = 0;
ind = CFI_setpointer(ptr, ptr, lower_bounds);