program qtest
type dog
integer :: woof
end type dog
type (dog), target :: terrier, dachshund
class (dog), pointer :: spot, fido
terrier%woof = 1
dachshund%woof = 2
spot => terrier
fido => dachshund
select type (spot)
type is (dog)
select type (fido)
type is (dog)
if (spot%woof .lt. fido%woof) spot => fido
end select
end select
print *, associated(spot, target=dachshund)
select type (woofer => spot)
type is (dog)
select type (fido)
type is (dog)
if (woofer%woof .lt. fido%woof) spot => fido
end select
end select
print *, associated(spot, target=dachshund)
end program qtest
At this point I think I understand roughly why the first method does
not work: spot acts as its target and not as itself within the select
type construct (or to put it another way, spot is an alias for terrier
and nothing more within the select type construct). I'm a bit
confused as to what the line
if (spot%woof .lt. fido%woof) spot => fido
actually does after compilation. Does it do anything? Or perhaps
more importantly, is that line conforming within the select type
construct? And, is there a better way to go about this than either of
the methods?
My nagfor 5.2 complains about that line:
Error: woof.f90, line 19: SPOT is not a POINTER
detected at SPOT@=>
[NAG Fortran Compiler pass 1 error termination, 1 error]
nagfor is probably right. If I read the standard correctly (8.1.5), the
first method associates the name 'spot' with the (target of) the
expression 'spot'. The name inherits some properties of the expression.
It doesn't inherit the pointer attribute because the pointer is
dereferenced before doing the association. Within the select type
construct, the associate name 'spot' shadows the variable 'spot'.
The same happens for 'fido', but the target attribute is inherited from
the expression 'fido', so this is no problem.
The second method does it right, I guess.
About what the compiler does with that line: it may issue an error
because the line is not standard-conforming. I don't know whether it is
required to issue an error.
-- Wolfgang
--
E-mail: firstnameini...@domain.de
Domain: yahoo
[snip program]
>> At this point I think I understand roughly why the first method does
>> not work: spot acts as its target and not as itself within the select
>> type construct (or to put it another way, spot is an alias for terrier
>> and nothing more within the select type construct). I'm a bit
>> confused as to what the line
>>
>> if (spot%woof .lt. fido%woof) spot => fido
>>
>> actually does after compilation. Does it do anything? Or perhaps
>> more importantly, is that line conforming within the select type
>> construct? And, is there a better way to go about this than either of
>> the methods?
>
> My nagfor 5.2 complains about that line:
>
> Error: woof.f90, line 19: SPOT is not a POINTER
> detected at SPOT@=>
> [NAG Fortran Compiler pass 1 error termination, 1 error]
xlf2003 complains about it also:
ftest : xlf2003 qtest.f90
"qtest.f90", line 19.35: 1515-038 (S) Only an object with the POINTER attribute is permitted on the left hand side of a
pointer assignment.
** qtest === End of Compilation 1 ===
1501-511 Compilation failed for file qtest.f90.
ftest : xlf2003 -qversion
IBM XL Fortran for AIX, V12.1
Version: 12.01.0000.0001
cheers,
paulv