What is the correct way to initialize a parameter array in fortran?

mgilson picture mgilson · Jan 28, 2013 · Viewed 13.9k times · Source

This works just fine:

  program main
    integer,parameter,dimension(3) :: x = [1,2,3]
    print*,x
  end program main

As does this:

  program main
    integer,parameter,dimension(3) :: x = (/1,2,3/)
    print*,x
  end program main

Is there a reason to think that one form should be preferred over the other (e.g. backward compatibility)?

Answer

IanH picture IanH · Jan 28, 2013

The square bracket form was added to the language in Fortran 2003. If you are writing to Fortran 90 (as per the tag on the question) then the square bracket form is a syntax error (square brackets are not in the Fortran 90 character set).

Beyond language standard it a question of personal preference and style.