Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

passing array to subroutine with common declaring array to have length 1

$
0
0

 Dear Developers,

I'm new in fortran programming and I found something that I can't understand clearly. I'm working with a complex code which uses a lot of subroutines in which array are passed by using the common declaration with the array size equal to 1. In the following I propose to you a simple example of what appened in this code:

      program COMMON_test
      parameter (MAX=5)
      COMMON/A1/A(MAX)
      DATA A(1),A(2),A(3),A(4),A(max)/1,1,1,1,1/
      CALL SUB
       end 
      
      subroutine SUB
      Parameter (MAX=5)
      COMMON/A1/A(1)
      DO I=2,MAX
          A(I)=A(I-1)+1
      END DO
      RETURN    
      END

This code run only if I deselect the "check array and string bounds". I tried to study what happened running the code line by line (with visual studio) and what I could understand is that in the subroutine SUB, A is not viewed as an array, in fact visual studio shows that it has only one element, but its actual elements, I mean A(2), A(3), A(4) and A(5), are modified by the subroutine instead.

I would appreciate if someone could explain me how this is possible.

Thanks very much for the attention

Ester


Viewing all articles
Browse latest Browse all 3270