Question about structures,intent(in),pointer elements

Rimvydas Jasinskas rimvydasjas@gmail.com
Sat Feb 1 14:56:00 GMT 2014


Just to be clear I understand that this *is* defined by f2003 and
f2008 standard:
      NOTE 5.13
      If a dummy argument is a derived-type object with a pointer
component, then the pointer as a
      pointer is a subobject of the dummy argument, but the target of
the pointer is not. Therefore, the
      restrictions on subobjects of the dummy object apply to the
pointer in contexts where it is used as
      a pointer, but not in contexts where it is dereferenced to
indicate its target. For example, if X is a
      dummy argument of derived type with an integer pointer component
P, and X has INTENT(IN),
      then the statement
      X%P => NEW_TARGET
      is prohibited, but
      X%P = 0
      is allowed (provided that X%P is associated with a definable target).

What worries me, that only easy way to detect this behaviour with gfortran
is by changing pointer->allocatable, that is very hard for deeply
nested structures.
Or alternatively use ifort, since it currently  rejects code like this...




On Sat, Feb 1, 2014 at 4:08 PM, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
> On Sat, Feb 01, 2014 at 01:17:44PM +0200, Rimvydas Jasinskas wrote:
>> Hello everyone,
>>
>> I am dealing with huge dinamic nested structures,
>> while refactoring code I came up with some issues.
>>
>> gcc version 4.8.2 20131219 (prerelease) (GCC) on ARCH
>>
>> There is an example:
>>
>> $ cat test_intent.f90
>> subroutine foo(bar1,bar2,bar3,bar4)
>>   implicit none
>>   type type1
>>     logical,pointer :: ll
>>   endtype type1
>>   logical            ,intent(in) :: bar1
>>   logical,allocatable,intent(in) :: bar2
>>   logical,pointer    ,intent(in) :: bar3
>>   type(type1)        ,intent(in) :: bar4
>>
>>   bar1=.false.
>>   bar2=.false.
>>   bar3=.false.
>>   bar4%ll=.false.
>> endsubroutine foo
>>
>> $ gfortran -c -Wall -Wextra test_intent.f90 -std=f2003
>>
>> I quite familiar with f95 std and I would naturally expect to have 4 errors:
>> Error: Dummy argument 'barX' with INTENT(IN) in variable definition
>> context (assignment)
>
> Understanding the lack of error with bar3=.false. may
> be related to the fact that you are not actually changing
> bar3.  You're changing the target associated with bar3.
> Add
>
>    logical, target :: foo3 = .true.
>    bar3=>foo3
>
> to your test.
>
> For the bar4 case, I need to re-read the standard, but
> I'm running out the door shortly.
>
> --
> Steve



More information about the Fortran mailing list