Module or main program array must have constant shape error in Fortran

前端 未结 1 2104
刺人心
刺人心 2021-01-14 12:49

An integer variable declared in the module is used as a global variable to define the size of related arrays in the program. The size of program varies, so the size of array

相关标签:
1条回答
  • 2021-01-14 13:42

    An array declared like a(n) is an explicit shape array. When n is not a constant (named or otherwise, strictly a constant expression) such an array is an automatic object.

    Automatic objects are restricted in where they may appear. In particular, an explicit shape array is subject to the following constraint (C531 of F2008):

    An explicit-shape-spec whose bounds are not constant expressions shall appear only in a subprogram, derived type definition, BLOCK construct, or interface body.

    As n from the module mod is not a constant it cannot be used as bounds of an array in the main program. The subroutine sub is a subprogram and so a(n) is a valid use of a non-constant bound.

    Instead of having an automatic object in the main program, one can instead consider deferred shape arrays, using either pointer or allocatable attributes.

    0 讨论(0)
提交回复
热议问题