FORTRAN on X86 : non equivalent variables in a module can have the same memory address.

Post Reply

Topic author
joukj
Master
Posts: 149
Joined: Thu Aug 27, 2020 5:50 am
Reputation: 0
Status: Offline

FORTRAN on X86 : non equivalent variables in a module can have the same memory address.

Post by joukj » Mon Nov 20, 2023 10:43 am

Hi

I get the following:

Code: Select all

rumba-jj) f90/vers
VSI Fortran x86-64 X8.5-007 (GEM 50XBD) on OpenVMS x86_64 V9.2-1  
rumba-jj) ty module_names.f90
module module_names
!
  integer ( kind = 4 ) :: r1( 21 ),r2(0:255 , 21 ),r3, &
&   r4 , r5(5),r6,r7,r6DEF, &
&   r8(5),r9,r10,r11,r9DEF, &
&   r12(5),r13,r14,r15,r13DEF, &
&   r16(5),r17,r18, &
&   r19(5),r20,r21 , r22( 18 )
  character ( len = 64 ) :: names( 0:501 )
  integer ( kind = 4 ) :: p1 , p2 , p3 , &
&   c2 , c3 = 125
  integer ( kind = 4 ) :: r1def , r10def
  logical ( kind = 4 ) :: p4( 21 )
  integer ( kind = 4 ) :: p5( 21 ) , p6( 0:501 &
&   ) , p7 , for_p1 , for_p3 , &
&   r4num , p8( 18 ) , p9 , p10
  integer ( kind = 1 ) :: p11
  logical ( kind = 4 ) :: p12 , unicode = .false.
  integer ( kind = 4 ) :: r22_part( 18 ) , no_defined_names
  integer ( kind = 4 ) :: c1
        character*64 names1( 0:50 ) , names2( 50 )
        character*64 names3( 50 ) , names4( 50 )
        character*64 names5( 50 ) , names6( 50 )
        character*64 names7( 50 ) , names8( 50 )
!
        equivalence( names( 0 ) , names1( 0 ) )
        equivalence( names( 51 ) , names2( 1 ) )
        equivalence( names( 101 ) , names3( 1 ) )
        equivalence( names( 151 ) , names4( 1 ) )
        equivalence( names( 201 ) , names5( 1 ) )
        equivalence( names( 251 ) , names6( 1 ) )
        equivalence( names( 301 ) , names7( 1 ) )
        equivalence( names( 351 ) , names8( 1 ) )
!
        data names1 / 51*' ' /
        data names2 / 50*' ' /
        data names3 / 50*' ' /
        data names4 / 50*' ' /
        data names5 / 50*' ' /
        data names6 / 50*' ' /
        data names7 / 50*' ' /
        data names8 / 50*' ' /
       data no_defined_names / 383 /
        DATA r5  /5*0/           
        DATA r8  /5*0/           
        DATA r12  /5*1/          
        DATA r16  /5*1/          
        DATA r19  /5*0/
        DATA r4    /5/             
        DATA r3    /0/             
        DATA r6      /0/
        DATA r9      /0/
        DATA r13      /1/
        DATA r17      /1/
        DATA r20      /0/
        data p1 /4/
        data p3 /5/
        data p2 /1/
        data c2 /5/
        data p7 / 0 /
        data for_p1 / 4 /
        data for_p3 / 5 /
                    data p9 /0/
!
end module module_names
  20-NOV-2023 16:37:10
rumba-jj) ty test.f90
program test
  use module_names

  integer i
  i = %loc( names )
  write(*,*) %loc( names ) , %loc( names8 )
  write(*,*) %loc(no_defined_names) , (%loc(no_defined_names) -i ) / 64
end
  20-NOV-2023 16:37:16
rumba-jj) f90 module_names
rumba-jj) f90 test.f90
rumba-jj) link test,module_names
rumba-jj) run test
                 8192                 30656
                 8192                     0
Two variables names and no_defined_names which are NOT equivalent seem to the same address (8192). This is not correct.
I tried to make the example simpler, but every time you change something to the module yoiu gert different results. I saw this problem also in other modules. All of them contained equivalence statements.

regards
Jouk
Last edited by joukj on Mon Nov 20, 2023 10:45 am, edited 1 time in total.


Topic author
joukj
Master
Posts: 149
Joined: Thu Aug 27, 2020 5:50 am
Reputation: 0
Status: Offline

Re: FORTRAN on X86 : non equivalent variables in a module can have the same memory address.

Post by joukj » Mon Jan 29, 2024 3:00 am

Looks like this is solved by the latest Fortran compiler

Post Reply