Sun Studio 12: Fortran Library Reference

1.4.33 long, short: Integer Object Conversion

long and short handle integer object conversions between INTEGER*4 and INTEGER*2, and is especially useful in subprogram call lists.

1.4.33.1 long: Convert a Short Integer to a Long Integer

The function is called by:

call ExpecLong( long(int2) )

int2

INTEGER*2

Input 

Return value 

INTEGER*4

Output 

1.4.33.2 short: Convert a Long Integer to a Short Integer

The function is:

INTEGER*2 short

call ExpecShort( short(int4) )

int4

INTEGER*4

Input 

Return value 

INTEGER*2

Output 

Example (fragment): long() and short():


       integer*4 int4/8/, long
       integer*2 int2/8/, short
       call ExpecLong( long(int2) )
       call ExpecShort( short(int4) )
       …
       end

ExpecLong is some subroutine called by the user program that expects a long (INTEGER*4) integer argument. Similarly, ExpecShort expects a short (INTEGER*2) integer argument.

long is useful if constants are used in calls to library routines and the code is compiled with the -i2 option.

short is useful in similar context when an otherwise long object must be passed as a short integer. Passing an integer to short that is too large in magnitude does not cause an error, but will result in unexpected behavior.