next up previous contents
Next: Scope Up: Program Units Previous: Local Objects

 

Argument Intent

 

In order to facilitate efficient compilation and optimisation hints, in the form of attributes, can be given to the compiler as to whether a given dummy argument will:

  1. hold a value on procedure entry which remains unchanged on exit -- INTENT(IN).
  2. not be used until it is assigned a value within the procedure -- INTENT(OUT).
  3. hold a value on procedure entry which may be modified and then passed back to the calling program -- INTENT(INOUT).

For example,
    SUBROUTINE example(arg1,arg2,arg3)
      REAL, INTENT(IN) :: arg1
      INTEGER, INTENT(OUT) :: arg2
      CHARACTER, INTENT(INOUT) :: arg3
      REAL r
       r = arg1*ICHAR(arg3)
       arg2 = ANINT(r)
       arg3 = CHAR(MOD(127,arg2))
    END SUBROUTINE example

It can be seen here that:

The use of INTENT attributes is not essential but it allows good compilers to check for coding errors thereby enhancing safety. If an INTENT(IN) object is assigned a value or if an INTENT(OUT) object is not assigned a value then errors will be generated at compile time.

Now try this question gif

Return to corresponding overview page gif


next up previous contents
Next: Scope Up: Program Units Previous: Local Objects

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.