On Tuesday, February 13, 2018 at 7:25:39 AM UTC-5,
john.coll...@gmail.com wrote:
@John,
> ..
>
> Is this the intended behaviour?
Per my simple-minded read of the standard, yes I surmise as much.
In 8.1.4 BLOCK Construct, the standard states, "specifications in a BLOCK construct declare construct entities whose scope is that of the BLOCK construct" and Note 8.5, "Actions on a variable local to a BLOCK construct do not affect any variable of the same name outside the construct."
> What happens with other compilers?
Intel Fortran compiler 18.0 update 1 (latest version) shows same behavior:
C:\Temp>type p.f90
SUBROUTINE t_variable_export
WRITE(*,'(//,"Test of export of a new implicitly declared variable")')
j = 1
BLOCK
i = 42
j = 42
WRITE(*,'("i inside BLOCK: ",I2)')i
WRITE(*,'("j inside BLOCK: ",I2)')j
END BLOCK
WRITE(*,'("i after BLOCK: ",I2)')i
WRITE(*,'("j after BLOCK: ",I2)')j
WRITE(*,'("End of test of export of a new variable")')
END SUBROUTINE t_variable_export ! ********************************************
call t_variable_export()
end
C:\Temp>ifort p.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R
) 64, Version 18.0.1.156 Build 20171018
Copyright (C) 1985-2017 Intel Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 14.12.25835.0
Copyright (C) Microsoft Corporation. All rights reserved.
-out:p.exe
-subsystem:console
p.obj
C:\Temp>p.exe
Test of export of a new implicitly declared variable
i inside BLOCK: 42
j inside BLOCK: 42
i after BLOCK: 0
j after BLOCK: 42
End of test of export of a new variable
> .. if you are working on compilers or program analysis tools you need to know
> whether to scan the entire environment around a BLOCK construct to determine
> which objects are in scope, or just up to the start of the BLOCK.
Can not a program analysis tool do what the 'mental compiler' of a Fortranner might do which is to view the code snippet you show in the original post like so?
SUBROUTINE t_variable_export
WRITE(*,'(//,"Test of export of a new implicitly declared variable")')
j = 1
call SUB_BLOCK( j )
WRITE(*,'("i after call SUB_BLOCK: ",I2)')i
WRITE(*,'("j after call SUB_BLOCK: ",I2)')j
WRITE(*,'("End of test of export of a new variable")')
END SUBROUTINE t_variable_export ! ********************************************
SUBROUTINE SUB_BLOCK(j)
i = 42
j = 42
WRITE(*,'("i inside SUB_BLOCK: ",I2)')i
WRITE(*,'("j inside SUB_BLOCK: ",I2)')j
END SUBROUTINE SUB_BLOCK