Assumed size arrays: Colon vs. asterisk - DIMENSION(:) arr vs. arr(*)
Solution 1:
The form
real, dimension(:) :: arr
declares an assumed-shape array, while the form
real :: arr(*)
declares an assumed-size array.
And, yes, there are differences between their use. The differences arise because, approximately, the compiler 'knows' the shape of the assumed-shape array but not of the assumed-size array. The extra information available to the compiler means that, among other things, assumed-shape arrays can be used in whole-array expressions. An assumed-size array can only be used in whole array expressions when it's an actual argument in a procedure reference that does not require the array's shape. Oh, and also in a call to the intrinsic lbound
-- but not in a call to the intrinsic ubound
. There are other subtle, and not-so-subtle, differences which your close reading of the standard or of a good Fortran book will reveal.
Some advice for new Fortran programmers is to use assumed-shape arrays when possible. They were not available before Fortran 90, so you will see lots of assumed-size arrays in old code. Assumed-shape arrays are better in new code, because the shape
and size
functions can be used to query their sizes to avoid out-of-bounds error and to allocate
arrays whose dimensions depend on the dimensions of input arrays.
Solution 2:
High Performance Mark's answer explains the difference between the two statements - in short: yes, there's a difference; only one declares an assumed-size array - and the implications.
However, as dimension(:)
but is mentioned, seemingly against not dimension(*)
, I'll add one thing.
real, dimension(:) :: arr1
real, dimension(*) :: arr2
is equivalent to
real :: arr1(:)
real :: arr2(*)
or even using dimension
statements. [I don't want to encourage that, so I won't write out the example.]
The important difference in the question is the use of *
and :
, not dimension
.
Perhaps there was some conflation of assumed-size with dummy argument? It is as a dummy argument where this choice is most common.