[J3] Question about the SAVE attribute
Daniel Chen
cdchen at ca.ibm.com
Thu May 29 16:05:05 UTC 2025
Thanks Brad!
Yeah, I found the following in the standard that supports your response.
```
If the dummy argument has the 1 TARGET attribute and the effective argument does not have the TARGET attribute or is an array section with a vector subscript, any pointers associated with the dummy argument become undefined when execution of the procedure completes.
If the dummy argument has the TARGET attribute and the VALUE attribute, any pointers associated with the
dummy argument become undefined when execution of the procedure completes.
```
Daniel
From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of Brad Richardson via J3 <j3 at mailman.j3-fortran.org>
Date: Thursday, May 29, 2025 at 11:36 AM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Brad Richardson <everythingfunctional at protonmail.com>
Subject: [EXTERNAL] Re: [J3] Question about the SAVE attribute
Your program is not standards conforming. Because the actual argument does not have the target attribute the association status of the pointer becomes undefined on exit from the procedure. Regards, Brad Richardson Making Everything Functional
Your program is not standards conforming. Because the actual argument does not have the target attribute the association status of the pointer becomes undefined on exit from the procedure.
Regards,
Brad Richardson
Making Everything Functional
Sent from Proton Mail Android
-------- Original Message --------
On 5/29/25 10:09 AM, Daniel Chen via J3 wrote:
Hello,
Consider the following code:
```
module m
contains
subroutine test(arg)
real, save, pointer :: ptr
real, optional, target :: arg !! What if I added VALUE attribute here?
if ( present(arg) ) then
ptr => arg
else
print*, ptr
endif
end
end module
program main
use m
call test(4.0 + 5.0)
call test()
End program```
The local pointer `ptr` has the SAVE attribute. It is associated with the target dummy argument `arg` when subroutine `test` is called the first time.
Should it preserve the association status at the 2nd call to `test`?
It seems the compilers I have access to indeed saved the pointer association status and prints `9.0`. But after I also added the VALUE attribute to `arg`, some compiler still saves the status but some don’t.
What is the standard conforming behavior here?
Thanks,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20250529/38f6ecc6/attachment.htm>
More information about the J3
mailing list