Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Intent of a derived type with a pointer component

22 views
Skip to first unread message

\"Vladimír Fuka <"name.surnameat

unread,
Apr 3, 2012, 8:55:07 AM4/3/12
to

I have a simple question. Is it allowed to assign to a pointee of a
pointer component of a derived type which is a dummy argument with intent
IN?

Vladimir
--
Tato zpráva byla vytvořena převratným poštovním klientem Opery:
http://www.opera.com/mail/

Steve Lionel

unread,
Apr 3, 2012, 10:42:52 AM4/3/12
to
On 4/3/2012 8:55 AM, \"Vladimír Fuka <\"name.surname at >> wrote:
>
> I have a simple question. Is it allowed to assign to a pointee of a
> pointer component of a derived type which is a dummy argument with
> intent IN?

Yes. This was a matter of much debate during the creation of the
Fortran 2003 standard, but in the end it was agreed that the intent
applies to the pointer itself, not the data it points to.

The current standard says (5.3.10): A pointer with the INTENT(IN)
attribute shall not appear in a pointer association context (16.6.8)

and then later:

The INTENT(IN) attribute for a pointer dummy argument specifies that
during the invocation and execution of the procedure its association
shall not be changed except that it may become undefined if the target
is deallocated other than through the pointer (16.5.2.5)

--
Steve Lionel
Developer Products Division
Intel Corporation
Merrimack, NH

For email address, replace "invalid" with "com"

User communities for Intel Software Development Products
http://software.intel.com/en-us/forums/
Intel Software Development Products Support
http://software.intel.com/sites/support/
My Fortran blog
http://www.intel.com/software/drfortran

Refer to http://software.intel.com/en-us/articles/optimization-notice
for more information regarding performance and optimization choices in
Intel software products.

\"Vladimír Fuka <"name.surnameat

unread,
Apr 3, 2012, 11:21:55 AM4/3/12
to
Thank you!

I was worried, because my Solaris Studio refuses even this simple example


type ptr
integer, pointer :: i
end type ptr

type(ptr) :: a
integer, target :: j

a%i => j
call sub(a,5)

print *,a%i

contains
subroutine sub(p,i)
type(ptr), intent(in) :: p
integer,intent(in) :: i
p%i = i
end subroutine
end


and gfortran-4.6 refuses my real world code, with


subroutine PoisFFT_Solver3D_FullPeriodic(D, Phi, RHS)
type(PoisFFT_Solver3D), intent(in) :: D
.
.
.

forall(i=1:D%nx,j=1:D%ny,k=1:D%nz)&
D%work(i,j,k) = cmplx(RHS(i,j,k),0._RP)


where PoisFFT_Solver3D is

type PoisFFT_Solver3D
.
.
.
complex(CP), dimension(:,:,:),&!contiguous,
pointer :: work => null()
end type PoisFFT_Solver3D


with

D%work(i,j,k) = cmplx(RHS(i,j,k),0._RP)
1
Error: Dummy argument 'd' with INTENT(IN) in variable definition context
(assignment) at (1)
poisfft.f90:95.6:


Best regards,

Vladimir


Dne Tue, 03 Apr 2012 16:42:52 +0200 Steve Lionel
<steve....@intel.invalid> napsal(a):

> On 4/3/2012 8:55 AM, \"Vladimír Fuka <\"name.surname at >> wrote:
>>
>> I have a simple question. Is it allowed to assign to a pointee of a
>> pointer component of a derived type which is a dummy argument with
>> intent IN?
>
> Yes. This was a matter of much debate during the creation of the
> Fortran 2003 standard, but in the end it was agreed that the intent
> applies to the pointer itself, not the data it points to.
>
> The current standard says (5.3.10): A pointer with the INTENT(IN)
> attribute shall not appear in a pointer association context (16.6.8)
>
> and then later:
>
> The INTENT(IN) attribute for a pointer dummy argument specifies that
> during the invocation and execution of the procedure its association
> shall not be changed except that it may become undefined if the target
> is deallocated other than through the pointer (16.5.2.5)
>


--

Tobias Burnus

unread,
Apr 3, 2012, 11:36:16 AM4/3/12
to
On 04/03/2012 05:21 PM, \"Vladimír Fuka <\"name.surname at >> wrote:
> and gfortran-4.6 refuses my real world code, with
> D%work(i,j,k) = cmplx(RHS(i,j,k),0._RP)
> 1
> Error: Dummy argument 'd' with INTENT(IN) in variable definition context

Could you try gfortran 4.6.3 or 4.7/4.8?

I think you run into the following bug, which was a 4.6 regression (i.e.
it should work with GCC 4.5). It has been fixed December 3, 2011. Thus,
the recently released 4.6.3 and 4.7.0 should work - as should newer
builds from the 4.6/4.7 branches and the 4.8 development trunk. (Sorry
for the breakage.) [There were also other fixes, but I think they only
applied to intent(in) with polymorphic dummy arguments.]

See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50684

Tobias

robert....@oracle.com

unread,
Apr 4, 2012, 12:08:58 AM4/4/12
to
On Apr 3, 8:21 am, \"Vladimír Fuka <\"name.surname at
<mffDOTcuniDOTcz">> wrote:
> Thank you!
>
>    I was worried, because my Solaris Studio refuses even this simple example
>
>   type ptr
>     integer, pointer :: i
>   end type ptr
>
>   type(ptr) :: a
>   integer, target ::  j
>
>   a%i => j
>   call sub(a,5)
>
>   print *,a%i
>
>   contains
>     subroutine sub(p,i)
>       type(ptr), intent(in) :: p
>       integer,intent(in) :: i
>       p%i = i
>     end subroutine
> end

I filed a change request for Oracle Solaris Studio Fortran.
The CR number is 7158858.

Robert Corbett

\"Vladimír Fuka <"name.surnameat

unread,
Apr 4, 2012, 3:06:35 AM4/4/12
to
I tried 4.6.3 and 4.7.0 20111219 from another machine. The problem still
persists. I will try to build a more recent version.

Vladimir

Dne Tue, 03 Apr 2012 17:36:16 +0200 Tobias Burnus <bur...@net-b.de>
napsal(a):

Steve Lionel

unread,
Apr 4, 2012, 10:34:07 AM4/4/12
to
On 4/3/2012 11:21 AM, \"Vladimír Fuka <\"name.surname at >> wrote:
> Thank you!
>
> I was worried, because my Solaris Studio refuses even this simple
> example

Well, Intel Fortran 12.1 does also, but I see this is fixed for the next
major release. As I said, it was a matter of contention and many
compilers initially took the "other" interpretation.
0 new messages