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

Robert Corbett rpcorbett at att.net
Tue Aug 7 13:53:54 EDT 2018


I agree with Van.  The expression L(N) is not a constant expression, but in the context in which it appears, it does not need to be a constant expression.

Bob Corbett

> On Aug 7, 2018, at 10:01 AM, 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
>> 
> 
> 



More information about the J3 mailing list