# Is pointing to a target dummy argument safe after return?

**URL:** <https://fortran-lang.discourse.group/t/is-pointing-to-a-target-dummy-argument-safe-after-return/5199>\
**Category:** Help\
**Created:** [February 13, 2023, 3:57pm UTC](https://fortran-lang.discourse.group/t/is-pointing-to-a-target-dummy-argument-safe-after-return/5199 "2023-02-13T15:57:18Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![aradi](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/aradi/32/3659_2.png) [@aradi](https://fortran-lang.discourse.group/u/aradi)\
**Post date:** [February 14, 2023, 9:00am UTC](https://fortran-lang.discourse.group/t/is-pointing-to-a-target-dummy-argument-safe-after-return/5199/8 "2023-02-14T09:00:59Z")

</div>

See also the discussion [Why/When is the `target` attribute part of the characterisics of a procedure](https://fortran-lang.discourse.group/t/why-when-is-the-target-attribute-part-of-the-characterisics-of-a-procedure/4826)

IMO, one should **never** use the `target` attribute for a dummy argument, **when** the pointer pointing to it is supposed to be valid after the scope had been left. It should work (in theory,) if the actual argument indeed has the `target` attribute (but only then!), but no compiler I know gives you any warning/error, if you actually forget to specify that attribute for the actual argument. So, sooner or later, it is bound to fail due to oversight (and it can be a mess to find the bug…)

I always specify the `pointer` attribute for the dummy argument in those cases, as all compilers I know will ensure that the actual argument has either the `pointer` or the `target` attribute. So you are safely pass back pointers to them as they are warranted to be valid also after the end of the scope and you won’t be hit by any copy-in/copy-out issues.

---

_[View the full topic](https://fortran-lang.discourse.group/t/is-pointing-to-a-target-dummy-argument-safe-after-return/5199)._
