FPT and WinFPT Reference Manual - Command-line Commands

### CHECK DATA TYPE COERCION

Syntax:

 [DO NOT] CHECK DATA TYPE [COERCION]

Function:

FPT checks all expressions for data type and data size (or kind) coercions which could lead to errors. It reports, for example:

• Integer expressions used in a context where logical expressions are expected.
• Integer assignments where a longer integer expression is assigned to a shorter variable. There is a risk of overflow in these cases. No report is made if the longer integer is explicitly converted by an intrinsic function, and no report is made if the longer expression is a compile-time constant which will fit within the shorter integer range.
• Assignments of integers from real expressions where there is no explicit conversion by an intrinsic function. There is a danger of overflow. Again, no report is made if the real expression is constant and is within the range of the integer assigned.
• Real expressions which contain real variables of different data sizes or kinds. There is often a loss of precision in these cases. No report is made if the conversion is made explicitly by an intrinsic function.

Mixed real sizes in expressions are a common source of error. For example:

! Emulation of VMS intrinsic dsind - R*8 sin in degrees REAL*8 FUNCTION dsind(theta) REAL*8 theta dsind = sin(theta*3.1415926535897932/180) END FUNCTION dsind

The problem here is not with the integer value 180. This will be promoted accurately to a REAL*8 value. The problem is PI. This is written with plenty of digits after the decimal point, but is a default REAL value, which on most systems is a REAL*4. The REAL*4 value of PI is then promoted to a REAL*8 value to be multiplied by theta, but the precision is already lost. The return from dsind occupies 8 bytes, but only has 4 bytes of precision. FPT traps the problem.

The use of integers in logical IF statements is common practice under VAX/VMS, and this causes problems when the software is ported to Unix or Windows.

The use of integers in logical IF statements is corrected automatically by the command CORRECT USE OF INTEGER FOR LOGICAL.

Where to use this command:

 Operating system command line Yes Configuration file, config.fsp Yes Specification (FSP) files, *.fsp Yes Interactively, to FPT> prompt: Yes Interactive command files Yes Embedded in the Fortran code Yes

Default:

A limited check of data type coercion is made by default. The full check is mode in response to this command (Note that defaults may be changed in the configuration file).

Example:

The user makes the interactive command:

FPT> ch data type

FPT reports:

```--------------------------------------------------------------
!!! ERROR !!! Number 1429 Severity 2 (Worst 1) Count 4 Line 32
File: D:\JOHN\FPT\FPTTEST\OPENFILE.FOR
IF (.NOT. STATUS) CALL LIB\$SIGNAL(%VAL(STATUS))
^
Inappropriate operand for .NOT.
--------------------------------------------------------------
--------------------------------------------------------------
!!! ERROR !!! Number 2533 Severity 2 (Worst 2) Count 5 Line 32
File: D:\JOHN\FPT\FPTTEST\OPENFILE.FOR
IF (.NOT. STATUS) CALL LIB\$SIGNAL(%VAL(STATUS))
^
Incorrect data type for this IF statement
--------------------------------------------------------------
```

and the subroutine code is marked:

STATUS=LIB\$GET_LUN(ICH) IF (.NOT. STATUS) CALL LIB\$SIGNAL(%VAL(STATUS)) !-----------------^------^------------------------------------ !!! FPT - 2533 Incorrect data type for this IF statement !!! FPT - 1429 Inappropriate operand for .NOT. !-------------------------------------------------------------

where STATUS is found to be an integer variable.