--------------------------------prog.f---------------------------------
PROGRAM MAIN
INTEGER X
X = 2
BLOCK
X = X + 1
DATA X/0/
PRINT *, X
END BLOCK
PRINT *, X
END -----------------------------------------------------------------------
I would like to know what results various
compilers produce for the program shown
above.
Robert Corbett <robertpa...@gmail.com> schrieb:
--------------------------------prog.f--------------------------------- PROGRAM MAIN
INTEGER X
X = 2
BLOCK
X = X + 1
DATA X/0/
PRINT *, X
END BLOCK
PRINT *, X
END -----------------------------------------------------------------------
I would like to know what results variousBoth gfortran and nagfor reject it:
compilers produce for the program shown
above.
$ gfortran x.f
x.f:6:16:
6 | DATA X/0/
| 1
Error: Host associated variable ‘x’ may not be in the DATA statement at (1)
$ nagfor x.f
NAG Fortran Compiler Release 7.1(Hanzomon) Build 7101
Error: x.f, line 6: Invalid redeclaration of host symbol X
detected at DATA@X
[NAG Fortran Compiler pass 1 error termination, 1 error]
..
I would like to know what results various
compilers produce for the program shown
above. ..
.. There is something missing
in the standard, and so the program is not standard
conforming because the standard does not
establish a meaning for the program. That hole in
the standard is what prompted me to ask the
question...
On Sunday, July 17, 2022 at 6:45:36 AM UTC-4, Robert Corbett wrote:which the standard has not made clear?
.. There is something missing
in the standard, and so the program is not standard
conforming because the standard does not
establish a meaning for the program. That hole in
the standard is what prompted me to ask the
question...
Bob,
It will be interesting to learn more from you re: the hole in the standard. Currently I fail to find any such hole, but I am surely overlooking something that you are not.
Is your understanding the standard as written currently permits the code you show in the original to get reduced *effectively* to the following whereas the processors are somehow following some unstated semantics to detect and report nonconformance but
INTEGER X
X = 3
DATA X/0/
PRINT *, X
END
By the way, I had presumed "DATA statement among executables" was now deleted from the standard: actually it is not! It is still supported, though it is marked as obsolescent.
program main
implicit none
integer :: i
do i=1,3
block
integer x
data x/0/
x = x + 1
print *, x
end block
enddo
end program main
Under "8.1.4 BLOCK construct" it states
2 Except for the ASYNCHRONOUS and VOLATILE statements, specifications
in a BLOCK construct declare construct entities whose scope is that
of the BLOCK construct (16.4).
I think that means the restriction is correct, in that the DATA statement
is specifying the initial saved valuea. So if the declaration for X is
in the block it would be OK, but not otherwise. This appears to work,
which supports that interpretation ...
program main
implicit none
integer :: i
do i=1,3
block
integer x
data x/0/
x = x + 1
print *, x
end block
enddo
end program main
In any case, this is something that a programmer should never do. Even
if the behavior is, now or in the future, specified by the language,
this is such an obscure corner case that no one should expect other programmers to know what is happening.
On 7/17/22 5:06 PM, John wrote:test1)$ gfortran /tmp/x2.f90
Under "8.1.4 BLOCK construct" it states
2 Except for the ASYNCHRONOUS and VOLATILE statements, specifications
in a BLOCK construct declare construct entities whose scope is that
of the BLOCK construct (16.4).
I think that means the restriction is correct, in that the DATA statement is specifying the initial saved valuea. So if the declaration for X is
in the block it would be OK, but not otherwise. This appears to work, which supports that interpretation ...
Yes, I think this issue does depend on how implicit typing applies toprogram main
implicit none
integer :: i
do i=1,3
block
integer x
data x/0/
x = x + 1
print *, x
end block
enddo
end program main
the block, and also how implied save applies to the data statment. Is
the x within the block a new implicitly typed variable, or is it the
same one outside the block. The explicit declaration within the block resolves that ambiguity.
I'm still uncertain about the DATA statement in that case. Does the DATA statement within the block change anything regarding the implicit typing?
In any case, this is something that a programmer should never do. Even
if the behavior is, now or in the future, specified by the language,
this is such an obscure corner case that no one should expect other programmers to know what is happening.
$.02 -Ron Shepard
A LONG time ago someone advised me to always take the well worn path when
I had a choice unless I liked filing compiler bugs. The advice still seems to be holding up.
On Monday, July 18, 2022 at 4:46:46 PM UTC-7, John wrote:
A LONG time ago someone advised me to always take the well worn path when
I had a choice unless I liked filing compiler bugs. The advice still seems to be holding up.
When I was first learning Fortran, first year of high school, I tended to do the opposite.
(And in driving, I have a tendency to go the path I haven't before, for variety or
to see new scenery.)
So, I was better than average at finding bugs in compilers, and other systems.
I would like to know what results various
compilers produce for the program shown
above. The compilers need to be of recent
vintage as the BLOCK construct was new
in Fortran 2008.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 159 |
Nodes: | 16 (0 / 16) |
Uptime: | 98:52:32 |
Calls: | 3,209 |
Files: | 10,563 |
Messages: | 3,009,783 |