Fortran allows parametrizing the size of elements of derived types. However, where fixed-size elements can have a default value assigned in the type declaration, there doesn't seem to be a way for parametrized entries:
PROGRAM main
IMPLICIT NONE
TYPE data1
INTEGER :: array(5) = 2 ! allowed
END type data1
TYPE data2(n)
INTEGER, LEN :: n
INTEGER :: array(n) = 2 ! incorrect: error #8737 with intel fortran 19,
END type data2 ! ignored by gfortran 8.2.1
END PROGRAM main
Assigning default values is convenient, as it allows avoiding repeating the initialization every time the type is used, but for parametric-sized fields it isn't allowed; Gfortran just ignores the default value silently, and Intel Fortran issues an error
error #8737: For a default initialized component every type parameter and array bound
must be a constant expression. [ARRAY]
Is there any syntax, that would allow defining a default value after all?