TRANSFER intrinsic function
Standard: F77 F90 F95 F2003 F2008
 Example Program
<Syntax>

TRANSFER ( SOURCE, MOLD [ , SIZE ] )

SOURCE : scalar or array of any type;
MOLD : scalar or array of any type;
SIZE : scalar Integer, not an optional dummy argument.

Result : same type and type parameters as MOLD, scalar if MOLD is scalar and SIZE is absent, otherwise an array of rank one.

<Semantics>

The result of this function has the same internal representation (bits in memory) as SOURCE, but with the type and kind of MOLD. If SIZE is present, it specifies the number of elements in the result; otherwise, if MOLD is an array, the number of elements is the fewest such that the storage size of the result is greater than or equal to the storage size of SOURCE, e.g. for a scalar SOURCE, STORAGE_SIZE(result)*SIZE(result)≥STORAGE_SIZE(SOURCE).

If the storage size of the result is greater than the storage size of SOURCE, the first part of the result has the same internal representation as SOURCE and the remainder is undefined (can be anything).

Note that it is possible for the result of TRANSFER to be an “impossible” value for the type, and in this case the results of further execution are not defined. This is especially true if the result type is LOGICAL; if the internal representation is neither that of .TRUE. or .FALSE., in some cases it will be interpreted as true and in other cases as false.

Another potential pitfall is transferring to a floating-point type; if the result has the form of an IEEE special value (e.g. a NaN), this can cause program termination with an invalid operation.

<Related>
SIZE intrinsic function, STORAGE_SIZE intrinsic function.