Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Can a passed-object dummy argument have the TARGET attribute?

Aldo_H_
初学者
820 次查看

The Fortran 2008 standard says (C456):

The passed-object dummy argument shall be a scalar, nonpointer, nonallocatable dummy data object
with the same declared type as the type being defined (...)

But can a passed-object dummy argument have the TARGET attribute? Should the Intel compiler be able to deal with this?

 

I am asking because I ran into segfaults with a type-bound function that returned a pointer to an attribute of the passed object. It was solved when I rewrote the code to use a regular subroutine. I'm also a little surprised that the standards committee allowed targets, but not pointers. I would just like to be sure that they did not simply forget to list 'target' in the above specifications.

 

0 项奖励
3 回复数
Juergen_R_R
重要分销商 II
820 次查看

Of course, it can have the target attribute:

module foo
  implicit none
  type :: t1
     integer :: n
   contains
     procedure :: init => t1_init
  end type t1

contains

  subroutine t1_init (t, n_in)
    integer, intent(in) :: n_in
    class(t1), intent(out), target :: t
    t%n = n_in
  end subroutine t1_init
end module foo

 

0 项奖励
Aldo_H_
初学者
820 次查看

Thanks for the reply. If this is actually common usage, then I suspect I just ran into a compiler glitch earlier.

By the way, your code sample does not use the fact that `t` is a target. It just shows that the compiler will not reject it, which I already knew.

0 项奖励
Juergen_R_R
重要分销商 II
820 次查看

No, I didn't make use of it, but is very common, e.g. for types containing run-time data which you want to have also in local instances, and which contain also pointer components like linked lists or parse trees and such. Then you need TBPs where the passed-object dummy argument is indeed a target.

0 项奖励
回复