mgilson
mgilson

Reputation: 309831

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

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)?

Upvotes: 14

Views: 19339

Answers (1)

IanH
IanH

Reputation: 21431

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.

Upvotes: 22

Related Questions