Quantcast
Channel: Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2583

Inconsistency between arguments, Valid ?

$
0
0

Hi,

I'm wondering is the following code is valid.

I'm defining a type bound procedure which has 2 argument:

  1. the passed-object dummy argument with the attribute 'intent(inout)'
  2. a integer variable with the attribute 'intent(in)'

If the actual argument associated to the dummy argument n°2 is a component of the passed-object dummy argument and if this component is modified in the TBP, then there is an inconsistency since the argument n°2 is declared as 'intent(in)' but its value is actually changing.

Below, an example which run without any warnings or errors

! ifort main.f90; ./a.out
Module MyModule
  implicit none
  private
  public        ::      MyType
  Type          ::      MyType
    integer     ::      Var
  contains
    procedure   ,public ::      Do_Something_Inconsistent
  End Type
  contains
Subroutine Do_Something_Inconsistent( This, Var )
  class(MyType)         ,intent(inout)  ::      This
  integer               ,intent(in)     ::      Var
  This%Var      =       Var + 1
End Subroutine
End Module
Program Main
  use MyModule  ,only:  MyType
  implicit none
  type(MyType)  ::      Obj
  Obj%Var       =       1
  write(*,"('BEFORE: Obj%Var = ',g0)") Obj%Var
  call Obj%Do_Something_Inconsistent( Obj%Var )         ! Is this valid
  write(*,"('AFTER:  Obj%Var = ',g0)") Obj%Var
End Program

sd


Viewing all articles
Browse latest Browse all 2583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>