Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
5 Views

Array constructor bracket syntax error?

Jump to solution

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

Accepted Solutions
Highlighted
Black Belt
5 Views

"Parameter" is only an

Jump to solution

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
Highlighted
Black Belt
6 Views

"Parameter" is only an

Jump to solution

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
Highlighted
Beginner
5 Views

Thanks!  I had tried using (

Jump to solution

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
Highlighted
Black Belt
5 Views

The PARAMETER declaration

Jump to solution

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
Highlighted
Black Belt
5 Views

I'm amused that (//) works

Jump to solution

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

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos