[J3] Question on component definition statement in a derived type involving a length-type parameter along with (apparently) constant expression

Bill Long longb at cray.com
Tue Aug 7 13:12:32 EDT 2018


 Array dimensions are one of the most common uses of PDT  length parameters.  In N would be acceptable, then L(N) should be as well where L is a constant array.  The definition looks OK to me.  At least one compiler accepts is with no message. 

Cheers,
Bill

> On Aug 7, 2018, at 12:01 PM, Van Snyder via J3 <j3 at mailman.j3-fortran.org> wrote:
> 
> On Tue, 2018-08-07 at 12:20 -0400, Steve Lionel via J3 wrote:
>> On 8/7/2018 12:06 PM, Vipul Parekh via J3 wrote:
>>> Is the following code standard-conforming?
>>> 
>>> --- begin code ---
>>>    integer, parameter :: L(*) = [ 1, 2, 3 ]
>>>    type :: t(N)
>>>       integer, len :: N
>>>       integer :: x( L(N) )       !<-- processors balk at L(N) in this
>>> component definition stmt
>>>    end type
>>> end
>>> --- end code ---
>>> 
>>> In the above code, L(N) appears to me a constant expression and which
>>> should make the component definition conform to the standard.  But the
>>> 2 compilers I tried throw errors.
>> 
>> Referencing 10-007: 4.2p5 says, "A length type parameter may be used in 
>> specification expressions within the derived-type definition for the 
>> type, but it shall not be used in constant expressions."
>> 
>> So, no, this is not standard conforming.
> 
> But the specification for a bound in a derived-type definition is not
> required to be a constant expression.  For example, in note 7.22 (in
> 18-007) a length parameter is used for an array bound.
> 
>> Steve
>> 
> 
> 

Bill Long                                                                       longb at cray.com
Principal Engineer, Fortran Technical Support &   voice:  651-605-9024
Bioinformatics Software Development                      fax:  651-605-9143
Cray Inc./ 2131 Lindau Lane/  Suite 1000/  Bloomington, MN  55425




More information about the J3 mailing list