4

The following program compiles with ifort (version 12) but not with GFortran (up to version 4.8):

PROGRAM TEST
IMPLICIT NONE
REAL,DIMENSION(2,2)::X=(/1,2,3,4/)

WRITE(*,*) X

END PROGRAM TEST

GFortran gives the error

REAL,DIMENSION(2,2)::X=(/1,2,3,4/)  
                       1  
Error: Incompatible ranks 2 and 1 in assignment at (1)

Ifort compiles the program and gives the expected output. Is this a bug in GFortran or does intel fortran simply allow non-standard array initialization?

1
  • Does it compile with a RESHAPE() statement in the initialization. Commented May 11, 2012 at 18:49

1 Answer 1

9

Re-write array declaration line as:

REAL,DIMENSION(2,2) :: X = RESHAPE([1,2,3,4],[2,2])

The reason ifort compiled it the other way is non-standard implementation. This is a way you can initialize arrays of rank higher than 1.

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

3 Comments

Beat me to it. See also this answer stackoverflow.com/a/3708370/623518. Strangely I cannot get ifort to complain about the OP's array initialisation, even with all the warning, error and standard version flags I can think of, even though I'm sure it is non-standard. Any thoughts?
Hmm...not sure. ifort is usually more strict than pgf90 when taking shortcuts, at least with the stuff I do, so I was a little surprised ifort allowed this. I have very little experience with gfortran though.
Thank you all. I knew already about the RESHAPE keyword. Was really just interested if ifort was accepting non-standard code. Seems that the answer is yes.

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.