Generic name for distinguishable pointers -
is possible use same generic name 2 pointers of different type? following of course doesn't work, should make clear mean:
real(4), pointer :: s_p real(8), pointer :: d_p generic :: p => s_p,d_p
for procdures these things can done interfaces defining destinguishable procedures module procedure
, type bound procedures there exists generic
type used similar given example. wonder if exists pointers too.
i'd mention unlimited polymorphic pointers (class(*)
) not want, since i'm trying generalize existing library double precision input, i'd have lot more work in implementing select type
blocks defining 2 pointers everywhere.
edit:
it of course possible associate same pointer variables of different type/kind. examples:
program test implicit none real(4),target :: real(8),target :: b class(*),pointer :: p a=2e0 b=3d0 p=>a call printer(p) a=a+4e0 call printer(p) p=>b call printer(p) associate (u=>a) ! me it's still miracle why works print*,u a=a+3e0 print*,u end associate associate (u=>b) print*,u end associate contains subroutine printer(p) class(*),pointer :: p select type (p) type (real(4)) p=p+2d0 ! wrong 2d0 gets converted correctly print*,p type (real(8)) print*,p end select end subroutine end program
my problem solution have implement select type
blocks everywhere in library pointer used. (at moment know it's many places.)
so main problem unlimited polymorphic pointer (p in example) stays polymorphic unless used inside select type
environement. of course necessary, since pointer everything. actual question is: there possibility tell polymorphic pointer in advance: can either or (e.g real(4) or real(8)) , depening on associated to, knows is?
the answer no, @ moment don't see, in situtation compliler might have problems distinguish between types/kinds.
no. data pointer variable. cannot have 2 different variables same name accessible in same scope.
if hypothetically could... in many cases compiler have no way of knowing variable meant when common name appeared.
the situation generic procedure names different - compiler can resolve specific procedure relevant when generic procedure name referenced examining number, types, kinds , ranks of arguments in procedure reference. rules of language ensure there can @ 1 such matching specific procedure, , generic procedure names not appear in contexts ability resolve relevant specific procedure not possible.
Comments
Post a Comment