3

In Fortran, are these two methods for initializing a parameter array identical? If not, what is the meaning of dimension(*)?

integer, parameter, dimension(2) :: x = [1,2]

vs

integer, parameter, dimension(*) :: x = [1,2]

0

1 Answer 1

5

The effect of both declarations is the same: a rank-1 named constant array of shape [2] with the obvious values.

Using dimension(*) makes the array implied shape rather than explicit shape: the named constant is of shape implied by the constant expression.

Which is better? Well, implied shape is not supported by all compilers (being a Fortran 2008 feature), but it saves worrying about writing shape twice.

Sign up to request clarification or add additional context in comments.

1 Comment

GCC >v7.1.1 and Intel ifort >2018 appear to support the implied shape.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.