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

The initial value of variables was changed when switching from other subroutine

$
0
0

Hi IVF,

A problem is found that the value of a variable declared in one subroutine will be changed by the IVF compiler after the code direction is switched from another subroutines. I made a test to show the problem with a test code as shown below.

====================================test code=============================================

program main

    implicit double precision(A-H,O-Z)

    call entry1

    call sub2

    call entry2

    write(*,*) "Test end."

end

subroutine sub1

    implicit double precision(A-H, O-Z)

    entry entry1

    Q=0.05

    write(*,*) "Before switching from entry1 to sub2, Q: ", Q

    pause

    return

    

    entry entry2

    write(*,*) "After the code switching from the sub2 to the sub1, Q:", Q

    pause

    return

end subroutine sub1

 

subroutine sub2

implicit double precision(A-H,O-Z)

!!............. (no declaration and precess is related to the variable Q)

return

end subroutine sub2

====================================test code=============================================

A variable Q with an initial value 0.05 is declared in the sub1, while no process is applied in the sub2.

Main program will enter the sub1 through the entry1, return to the main, enter the sub2, return to the main, and then enter the sub1 through the entry2. The values of Q in the sub1 at the entry1 and entry2 are outputted on the monitor.

The result of the test is shown in the following figure. The value of Q before switching to the sub2 is the same as the declaration, while it changed to an extremely large negative value automatically when the code get back to the sub1 from the sub2.

The test code can work normally (Q values are the same) with the old Fortran compiler (e.g. Digital VIsual Fortran) so I think the problem would be due to the IVF.



Any suggestion?   

v[[{"fid":"315938","view_mode":"default","fields":{"format":"default","field_file_image_alt_text[und][0][value]":"","field_file_image_title_text[und][0][value]":"variable Q is canged by the switching between subrutines","field_tags[und]":""},"type":"media","attributes":{"title":"variable Q is canged by the switching between subrutines","height":116,"width":644,"class":"media-element file-default"}}]]


Viewing all articles
Browse latest Browse all 3270

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>