[J3] [EXTERNAL] Re: Is this legal in F202X? Rank agnosticism and scalars
Clune, Thomas L. (GSFC-6101)
thomas.l.clune at nasa.gov
Tue Jan 24 14:00:08 UTC 2023
Hi Vipul,
For some reason my initial reply from my home computer did not go out last evening. (Although then my useless-on-its-own response from my iPad did go out to add to my confusion.)
With N=0, RANK(N) is used to declare a scalar. So your examples in your first response are not relevant. Your second response correctly has A as a scalar, but the print statement still needs the @. So the proper instantiation of the template should produce a procedure like:
REAL FUNCTION FIRST_ELEMENT(A)
REAL, INTENT(IN) :: A
INTEGER :: idx(0)
idx = 1
PRINT*, A(@idx) ! is this legal for N=0
END REAL
I think the @ is essential here, as otherwise one certainly cannot index a scalar, and risks being interpreted as a vector subscript in any event.
If something like this cannot be permitted then it will generally limit the ability to use RANK(N) for the scalar case to whole array operations. It cannot even be guarded with a conditional ala:
IF (N > 0) THEN
PRINT*, A(@idx)
ELSE
PRINT*, A
END IF
As the compiler can rightly insist that the first print is still illegal syntax even if unreachable.
* Tom
From: Vipul Parekh <parekhvs at gmail.com>
Date: Monday, January 23, 2023 at 7:11 PM
To: j3 <j3 at mailman.j3-fortran.org>
Cc: "Clune, Thomas L. (GSFC-6101)" <thomas.l.clune at nasa.gov>
Subject: [EXTERNAL] Re: [J3] Is this legal in F202X? Rank agnosticism and scalars
On Mon, Jan 23, 2023 at 7:05 PM Vipul Parekh <parekhvs at gmail.com<mailto:parekhvs at gmail.com>> wrote:
..
Does the code you show reduce to the following?
integer :: a(0)
integer :: idx(0) .
Or as does the code you show reduce to the following?
integer :: a
integer :: idx(0)
a = 42
idx = 1
print *, a(idx)
end
in which case the reference to `a` in the PRINT statement is nonconforming?
Thanks,
Vipul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20230124/25d58812/attachment.htm>
More information about the J3
mailing list