Difficulty with fortran variable

I have included one variable in one of the fortran functions. I use it in another function. But the meaning does not remain the same. In another function call, I get the garbage value. How to save the initialized value.

Example:

entry a ()
num_calls = 0

entry b ()
num_calls = num_calls + 1

From the entry "b" I get num_calls as some trash

+3
source share
4 answers

In classic Fortran (Fortran 77 or earlier), you need to make sure that num_calls is defined in a common block - perhaps a named common block.

COMMON /magic/ num_calls

Fortran 90, , . , , , , - .

. :

INTEGER*4 num_calls
COMMON /magic/ num_calls
+5

FORTRAN 77 , , Fortran 90 COMMON. , Fortran 90/Fortran 2003, COMMON - GOTO ENTRY.

Fortran 90 ( ) COMMON, a MODULE. :

module count_calls

    integer :: num_calls = 0

end module count_calls

, num_calls,

use count_calls

, ( a program MODULE).

+4

num_calls , . -, FORTRAN, ...

+1

"save". , . , "", .

    integer*4, save :: num_calls

This is a standard feature in most languages ​​when local variables go undefined when they go out of scope.

+1
source

Source: https://habr.com/ru/post/1713124/


All Articles