 
  
  
  
  
 Next: Scope
Up: Program Units
 Previous: Local Objects
 
 
 
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:
-  hold a value on procedure entry which remains unchanged on exit --
INTENT(IN).
-  not be used until it is assigned a value within the procedure
-- INTENT(OUT).
-  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:
-  arg1 is unchanged within the procedure,
-  the value of arg2 is not used until it has been assigned to,
-  arg3 is used and then reassigned a value.
 
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  
Return to corresponding overview page  
 
  
  
  
  
 Next: Scope
Up: Program Units
 Previous: Local Objects
©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997Not for commercial use.