What is the correct way to initialize an array of parameters in fortran?

This works great:

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

How does it do:

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

Is there any reason to think that one form should be preferred over another (for example, backward compatibility)?

+4
source share
1 answer

The shape of the square bracket was added to the language in Fortran 2003. If you write in Fortran 90 (according to the tag in the question), the shape of the square bracket is a syntax error (square brackets are not in the Fortran 90 character set).

In addition to the locale, this is a matter of personal preference and style.

+15
source