Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.

Structure Constructor

ferrad01
Beginner
469 Views
I am trying to use a structure constructor to initialize my variable. I couldn't get it working, so I tried an example I found on the IBM website (http://publib.boulder.ibm.com/infocenter/lnxpcomp/v101v121/index.jsp?topic=/com.ibm.xlf121.linux.doc/language_ref/structure_constructor.html):

PROGRAM NEW_LOCAL
TYPE DT
INTEGER :: A = 20
INTEGER :: B = 80
END TYPE

TYPE(DT):: DT_VAR = DT()
TYPE(DT):: DT_VAR2 = DT(B=40)
TYPE(DT):: DT_VAR3 = DT(B=10, A=50)

PRINT *, 'DT_VAR =', DT_VAR
PRINT *, 'DT_VAR2=', DT_VAR2
PRINT *, 'DT_VAR3=', DT_VAR3
END PROGRAM NEW_LOCAL

However I get an error:

D:\test>ifort test2.f90
Intel Visual Fortran Compiler for applications running on IA-32, Version 10.1 Build 20080312 Package ID: w_fc_p_10.1.021
Copyright (C) 1985-2008 Intel Corporation. All rights reserved.

test2.f90(7) : Error: The number of expressions in a structure constructor differs from the number of components of the derived type [DT]
TYPE(DT):: DT_VAR = DT()
---------------------^
compilation aborted for test2.f90 (code 1)

What is the problem?
0 Kudos
3 Replies
Jugoslav_Dujic
Valued Contributor II
469 Views
Quoting - ferrad01
I am trying to use a structure constructor to initialize my variable. I couldn't get it working, so I tried an example I found on the IBM website (http://publib.boulder.ibm.com/infocenter/lnxpcomp/v101v121/index.jsp?topic=/com.ibm.xlf121.linux.doc/language_ref/structure_constructor.html):

PROGRAM NEW_LOCAL
TYPE DT
INTEGER :: A = 20
INTEGER :: B = 80
END TYPE

TYPE(DT):: DT_VAR = DT()
TYPE(DT):: DT_VAR2 = DT(B=40)
TYPE(DT):: DT_VAR3 = DT(B=10, A=50)

PRINT *, 'DT_VAR =', DT_VAR
PRINT *, 'DT_VAR2=', DT_VAR2
PRINT *, 'DT_VAR3=', DT_VAR3
END PROGRAM NEW_LOCAL

However I get an error:

D:test>ifort test2.f90
Intel Visual Fortran Compiler for applications running on IA-32, Version 10.1 Build 20080312 Package ID: w_fc_p_10.1.021
Copyright (C) 1985-2008 Intel Corporation. All rights reserved.

test2.f90(7) : Error: The number of expressions in a structure constructor differs from the number of components of the derived type [DT]
TYPE(DT):: DT_VAR = DT()
---------------------^
compilation aborted for test2.f90 (code 1)

What is the problem?

As the IBM page stresses, using keyword arguments in the constructor is a Fortran 2003 feature, which is not implemented in IVF 10.1. A quick check shows that it's not implemented in 11.0.061 either.
0 Kudos
ferrad01
Beginner
469 Views
Quoting - Jugoslav Dujic
Quoting - ferrad01
I am trying to use a structure constructor to initialize my variable. I couldn't get it working, so I tried an example I found on the IBM website (http://publib.boulder.ibm.com/infocenter/lnxpcomp/v101v121/index.jsp?topic=/com.ibm.xlf121.linux.doc/language_ref/structure_constructor.html):

PROGRAM NEW_LOCAL
TYPE DT
INTEGER :: A = 20
INTEGER :: B = 80
END TYPE

TYPE(DT):: DT_VAR = DT()
TYPE(DT):: DT_VAR2 = DT(B=40)
TYPE(DT):: DT_VAR3 = DT(B=10, A=50)

PRINT *, 'DT_VAR =', DT_VAR
PRINT *, 'DT_VAR2=', DT_VAR2
PRINT *, 'DT_VAR3=', DT_VAR3
END PROGRAM NEW_LOCAL

However I get an error:

D:test>ifort test2.f90
Intel Visual Fortran Compiler for applications running on IA-32, Version 10.1 Build 20080312 Package ID: w_fc_p_10.1.021
Copyright (C) 1985-2008 Intel Corporation. All rights reserved.

test2.f90(7) : Error: The number of expressions in a structure constructor differs from the number of components of the derived type [DT]
TYPE(DT):: DT_VAR = DT()
---------------------^
compilation aborted for test2.f90 (code 1)

What is the problem?

As the IBM page stresses, using keyword arguments in the constructor is a Fortran 2003 feature, which is not implemented in IVF 10.1. A quick check shows that it's not implemented in 11.0.061 either.

Thanks, yes I saw it was a Fortran 2003 feature. I had assumed that 2003 features would be available in IVF by now.
0 Kudos
Steven_L_Intel1
Employee
469 Views
Many are, but that particular feature is coming later this year.
0 Kudos
Reply