[J3] Question about the SAVE attribute
Brad Richardson
everythingfunctional at protonmail.com
Thu May 29 15:36:08 UTC 2025
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/473a9c5a/attachment-0001.htm>
More information about the J3
mailing list