[J3] [EXTERNAL] [BULK] Re: Question on dummy CLASS(*) pointer arguments
Clune, Thomas L. (GSFC-6101)
thomas.l.clune at nasa.gov
Thu Nov 30 14:07:53 UTC 2023
Malcolm,
Yes – that is indeed my intention. The current code does use TARGET for the dummy argument but results in semi-obscure run time errors when the actual argument does not have the TARGET attribute. The code in question is part of asynchronous communication layer in which I save addresses of arrays (C_LOC) which are then copied upon a signal at a later time.
The irony of course is that despite relying on nonstandard behavior, most compilers “get it right”. NAG finds it at runtime with debugging on, but at some point it feels more like I’m working around a defect in the compiler than a bug in my code. (I emphasize “feels”.)
This problem most often arises for me when the passed-object dummy argument would most benefit from using the POINTER attribute. Alas that is also forbidden. So, when I encountered the case discussed in this thread, I was delighted to explain to a person on my team why we should change to using POINTER, only to find out it won’t work. Sigh.
Cheers,
* Tom
From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of j3 <j3 at mailman.j3-fortran.org>
Reply-To: j3 <j3 at mailman.j3-fortran.org>
Date: Wednesday, November 29, 2023 at 11:37 PM
To: j3 <j3 at mailman.j3-fortran.org>
Cc: Malcolm Cohen <malcolm at nag-j.co.jp>
Subject: [EXTERNAL] [BULK] Re: [J3] Question on dummy CLASS(*) pointer arguments
CAUTION: This email originated from outside of NASA. Please take care when clicking links or opening attachments. Use the "Report Message" button to report suspicious messages to the NASA SOC.
This makes me wonder why this is CLASS(*),POINTER,INTENT(IN) at all?
CLASS(*),TARGET would work, and also permit passing non-pointer/target actual arguments. Maybe that is the reason, that you want to require the actual argument to be a target? Are you sure you really want to do that?
Making this valid would probably require a lot of extra words to make sure nothing gets broken. It is certainly not obvious that there is any functionality here worth the additional complication of the language.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Clune, Thomas L. (GSFC-6101) via J3
Sent: Thursday, November 30, 2023 2:45 AM
To: j3 <j3 at mailman.j3-fortran.org>
Cc: Clune, Thomas L. (GSFC-6101) <thomas.l.clune at nasa.gov>
Subject: [J3] Question on dummy CLASS(*) pointer arguments
Consider the code below:
program main
implicit none
real, pointer :: y(:)
allocate(y(2))
call s(y)
contains
subroutine s(x)
class(*), pointer, intent(in) :: x(:)
end subroutine s
end program main
This is disallowed by the standard, presumably because the pointer array x could become associated with some other type. However, since the dummy pointer has the INTENT(IN) attribute, I do not immediately see what could go wrong. Is it simply that processors may want to have different representations for POINTER objects that we don’t want to force the conversion here?
Thanks,
- Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20231130/564857f4/attachment-0001.htm>
More information about the J3
mailing list