J3/04-143 Date: 26 Dec. 2003 To: J3 From: Dan Nagle Subject: Proposed ASSERT in Interfaces Placing assertions into programs serves at least three purposes: First, they provide a simple means of debugging; Second, they document the programmer's intentions; Third, they provide a means to allow the compiler gain information which might require entire application analysis, if it could be gleened at all. If assertions are accepted, they should be allowed to appear in interfaces, where both caller and callee benefit. Number: Title: ASSERT in Interfaces Submitted By: J3 Status: For Consideration References: Basic Functionality: Make an extension of the executable ASSERT statement to procedure interfaces, where it can apply to intent(in) arguments, and to intent(out) arguments and function results. Rationale: Extending assertions to interfaces allows checking argument values by either caller or callee. Many Fortran procedures correspond to mathematical theorems, verifying the premises and then the results is natural for these ubiquitous procedures. Estimated Impact: Two new declarations must be supported in interfaces, no other statement is affected. Detailed Specification: Two declarations are needed, one applies at the time of the call, the other at time of return. Whether checked by caller or callee is not specified, both are known to both sides. I suggest "as-if" language along the lines of "when argument association is made" or "when argument association ceases" or some such. PREMISE( ) This declaration applies to intent( in) dummy arguments and intent( inout) dummy arguments at time of the call. PROPERTY( ) This declaration applies to intent( out) dummy arguments, intent( inout) dummy arguments, and function result variables at time of return. An is as defined for the ASSERT statement. Example: interface real function fourth_root( x) real, intent( in) :: x premise( x >= 0.0, level= assert_halt) property( abs( fourth_root**4 - x) < tol, & level= assert_warn) end function fourth_root end interface When fourth_root is called, the program will print a message to stderr and stop if x < 0.0. Otherwise, if the fourth_root is not within tolerance, the program will print a message to stderr and continue when fourth_root returns. History: