6

Consider

INTEGER,DIMENSION(3) :: NumberVector

and

INTEGER              :: NumberVector(3)

Is there any difference whatsoever between these two declarations or are they exactly the same? (I mean in ANY possible context and variation: for example, in the case that those two were identical, what if I am declaring an array with an implicit size as one of the input parameter of a subroutine? Would it still be irrelevant which one I used?)

2 Answers 2

8

Yes, it is identical. Even for assumed, deferred and whatever possible shape.

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

Comments

3

The DIMENSION attribute was added to Fortran 90 in order to improve code clarity and to enable code savings when declaring multiple arrays of the same type (not uncommon in scientific computing), e.g. instead of

REAL :: mat1(10,20), mat2(10,20), mat3(10,20), mat4(10,20), mat5(10,20)

one could write

REAL, DIMENSION(10,20) :: mat1, mat2, mat3, mat4, mat5

Besides reducing source code size and compilation time (less parsing; not that relevant nowadays), this reduces the possibility of making a mistake in any of the declarations. Otherwise both forms are equal and the variables declared behave exactly the same way everywhere in the program.

1 Comment

DIMENSION as a "keyword" existed well before Fortran 90, it was even in FORTRAN IV (66) as a statement. Fortran 90 only added the possibility of using these statements (such as PARAMETER,SAVE or DIMENSION) as an attribute in a variable declaration.

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.