Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29389 Discussions

Is it possible to declare and initialize a derived type parameter array?

OP1
New Contributor III
1,086 Views

I would like to define a parameter structure array, that is, an array of derived type components which would be a parameter. Thiswould look like something like this:

INTEGER,PARAMETER :: MAX_SYMBOL_NAME_LENGTH = 63

TYPE T_ID

INTEGER :: ID

CHARACTER(LEN=MAX_SYMBOL_NAME_LENGTH) :: NAME

END TYPE T_ID

TYPE(T_ID),PARAMETER :: IDS(1) = [ (1,'test') ]

This triggers a compiler error - the syntax is not valid. Obviously I want more than one element in my array - this is just for illustration purposes. I am wondering if this is possible, and if yes what is the proper syntax.

Thanks!

Olivier

0 Kudos
2 Replies
Steven_L_Intel1
Employee
1,086 Views

You're close. You need the type name in the structure constructor. For example:

[fortran]TYPE(T_ID),PARAMETER :: IDS(2) = [T_ID(1,'test'),T_ID(2,'moretest')][/fortran]

(Hmm - that should all be on one line...)

0 Kudos
OP1
New Contributor III
1,086 Views

Ah, that works beautifully. Thanks Steve!

0 Kudos
Reply