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

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?

1 Like