# Why/When is the \`target\` attribute part of the characterisics of a procedure

**URL:** <https://fortran-lang.discourse.group/t/why-when-is-the-target-attribute-part-of-the-characterisics-of-a-procedure/4826>\
**Category:** Uncategorized\
**Created:** [November 29, 2022, 4:01pm UTC](https://fortran-lang.discourse.group/t/why-when-is-the-target-attribute-part-of-the-characterisics-of-a-procedure/4826 "2022-11-29T16:01:35Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [November 30, 2022, 10:41am UTC](https://fortran-lang.discourse.group/t/why-when-is-the-target-attribute-part-of-the-characterisics-of-a-procedure/4826/3 "2022-11-30T10:41:06Z")

</div>

> [@FortranFan](#):
>
> The standard has long permitted the extension where the effective argument need **not** have the `TARGET` attribute in a call to a procedure with an explicit interface where the corresponding received argument has the `TARGET` attribute.

OK, thanks, it is good to know, that the “workaround” with the helper function is standard conforming at least. Still, I am still wondering, **why** the `target` attribute is part of the characteristic of a procedure at all?

When a procedure declaring a dummy argument with the `target` attribute is called, there are two possibilities:

- The caller passes an actual argument _with_ the `target`/`pointer` attribute. If I understand it correctly now, in this case all pointers associated with the dummy argument will remain valid also after the exit from the procedure (and will be associated with the actual argument).

- The caller passes an actual argument _without_ the `target`/`pointer` attribute. In this case, all pointers associated with the dummy argument will become invalid after the exit from the procedure.

So, if I understand correctly, a procedure can never safely assume, that pointers it associates with a dummy argument with the `target` attribute remain valid after the exit, as it depends on how the procedure was called, which is beyond its control.

Therefore, in order to ensure deterministic behavior for all possible calls, a procedure should

- either specify the `target` attribute for a dummy argument, and then avoid to pass back or save any pointers it associates with that target (as the processor will not ensure, that the actual argument has the `target`/`pointer` attribute)

- or specify the `pointer` attribute for a dummy argument, as then all pointers associated with that dummy argument will remain valid after exit. (as the processor will enforce the caller to specify the `target` or the `pointer` attribute for the actual argument)

So, to me it seems, there are no scenarios, where in a robust programming model, the `target` attribute of a dummy argument should be used to anything else, as associating and using pointers to that argument **within the declaring procedure only**. So, it becomes an “internal affair” which the caller would not need to be aware of.

Do I overlook anything?

---

_[View the full topic](https://fortran-lang.discourse.group/t/why-when-is-the-target-attribute-part-of-the-characterisics-of-a-procedure/4826)._
