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/pointerattribute. 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/pointerattribute. 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
targetattribute 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 thetarget/pointerattribute) -
or specify the
pointerattribute 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 thetargetor thepointerattribute 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?