4

この質問は、私の前の質問に関連しています:コンパイラに省略された意図を意図 (inout) として解釈させる方法。省略されたインテントをインテント(inout)として解釈することは不可能に見えるため、インテント(in)の違反の問題は依然として存在します。

同じ例:

module test
  implicit none
  contains

  subroutine fun1(x)
    real(8), intent(in)::x
    call fun2(x)               
  end subroutine

  subroutine fun2(x)
   real(8) :: x
   x = 10
  end subroutine
end module

このコードは、gfortran と ifort によってエラー/警告なしでコンパイルできます。だから私の質問は:

インテント(in)変数がインテントを省略してサブルーチンに渡されたときに、Fortranコンパイラにエラーを生成させる方法は?

4

1 に答える 1

2

IanHが言ったように、これを拾うことができるプロセッサ(つまりコンパイラ)が必要です。たとえば、適切なフラグを指定すると、NAGコンパイラは(免責事項-私はNAGで動作します)実行します。コードを少し変更して移植可能にし、これを示すドライバーを追加しました。

$ cat t.f90 
module test
  implicit none

  Integer, Parameter :: wp = Selected_real_kind( 12, 70 )

  contains

  subroutine fun1(x)
    real(wp), intent(in)::x
    call fun2(x)               
  end subroutine

  subroutine fun2(x)
   real(wp) :: x
   x = 10
  end subroutine
end module

Program test_test

  Use test

  Implicit None

  Real( wp ) :: x

  x = 5.0_wp

  Call fun1( x ) 

End Program test_test
$ nagfor t.f90
NAG Fortran Compiler Release 5.3.1 pre-release(904)
[NAG Fortran Compiler normal termination]
$ ./a.out
$ nagfor -C=all -C=undefined t.f90 
NAG Fortran Compiler Release 5.3.1 pre-release(904)
[NAG Fortran Compiler normal termination]
$ ./a.out
Runtime Error: t.f90, line 15: Dummy argument X is associated with an expression - cannot assign
Program terminated by fatal error
Aborted (core dumped)
$ 

したがって、フラグを検索してください。コンパイラを提供する人に文句を言わない限り、役立つことがあるかもしれません。

于 2012-10-10T10:51:13.873 に答える