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

Array constructor bracket syntax error?

j0e
New Contributor I
2,042 Views

This program:

   Program testArrayCon
      implicit none
      real(8), dimension(2):: t1, t2
      parameter t1 = (/1.0, 2.0/)
      parameter t2 = [3.0, 4.0]
   end program testArrayCon

produces the following syntax error associated with the assignment of t2:

 error #5082: Syntax error, found '.' when expecting one of: .EQV. .NEQV. .XOR. .OR. .AND. .LT. < .LE. <= .EQ. == .NE. /= .GT. > ...

I don't see why I can't use the [ ] array constructor in the parameter statement.  In a type declaration, they are fine:

   Program testArrayCon
      implicit none
      real(8), dimension(2), parameter:: t1 = [1.0, 2.0]
      real(8), dimension(2), parameter:: t2 = [3.0, 4.0]
   end program testArrayCon

I'm using Update 3 of Intel Fortran 2018 cluster studio (which is the latest version).

Cheers, joe

0 Kudos
1 Solution
mecej4
Honored Contributor III
2,042 Views

Please look up the syntax for specifying initial values in a PARAMETER statement in section 5.2.9 of the Fortran 2003 standard. You need to enclose the list of initialized variables and expressions in a pair of parentheses:

parameter (t1 = (/1.0, 2.0/), t2 = [3.0, 4.0])

 

View solution in original post

0 Kudos
4 Replies
mecej4
Honored Contributor III
2,043 Views

Please look up the syntax for specifying initial values in a PARAMETER statement in section 5.2.9 of the Fortran 2003 standard. You need to enclose the list of initialized variables and expressions in a pair of parentheses:

parameter (t1 = (/1.0, 2.0/), t2 = [3.0, 4.0])

 

0 Kudos
j0e
New Contributor I
2,042 Views

Thanks!  I had tried using ( ) as specified, but it generated errors (but they may have been caused by something else).  I have some other code where I did not use ( ) in the PARAMETER statement, and no errors were produced.  Likewise, this compiles fine,

parameter t1 = (/1.0, 2.0/)

However, you are correct, that adding the ( ) does solve the problem when using [] array specifiers.  I suppose the above should also generate a syntax error, but it doesn't, which was the confusing bit.

Thanks for your help!!

0 Kudos
mecej4
Honored Contributor III
2,042 Views

The PARAMETER declaration without parentheses was an extension created by DEC, and is not part of standard Fortran. Intel Fortran supports many DEC extensions by default, and you have to specify /standard-semantics to have the compiler flag non-standard extensions.

0 Kudos
Steve_Lionel
Honored Contributor III
2,042 Views

I'm amused that (//) works and [] doesn't, but I can guess why. I'll comment that the non-standard PARAMETER syntax (it was in a draft F77 standard but then got changed) has somewhat different semantics than the standard version, and I don't recommend using it unless you need those exact semantics.

In my opinion, both constructor syntaxes should be accepted - please report this bug to Intel using https://supporttickets.intel.com/?lang=en-US

0 Kudos
Reply