(j3.2006) Constraint C835: SELECT TYPE selector must be a namedvariable

Malcolm Cohen malcolm
Fri Nov 7 01:14:49 EST 2014


Damian asks (in a message I only just received due to technical reasons):
<<<
Could someone tell me the motivation for the following constraint on ?select 
type? selectors in the Fortran 2008 standard?

C835 (R847) If selector is not a named variable, associate-name => shall appear.
>>>

Because we want the associate name to be a name...

Basically, the fundamental syntax is
  SELECT TYPE (associate-name => selector)
it is just that it is convenient to be able to leave the "associate-name =>" 
part out when you have a simple polymorphic variable name, so when the selector 
is a named variable, we allow you to leave it out.  Thus
   SELECT TYPE(polyvar)
is short for
   SELECT TYPE( polyvar => polyvar )

Could we have made SELECT TYPE work without that?  Sure, but it would be more 
complicated, and more (perhaps much more) work to implement.

For example, consider

  TYPE t
    CLASS(basetype),POINTER :: ptr
  END TYPE
  TYPE(t) a(100)
  ...
  I = 1
  J = 1
  SELECT TYPE (a(i)%ptr)
  TYPE IS (sometype)
     do something with A(I)%ptr
     do something with A(I*1)%ptr
     do something with A(J)%ptr
  ...

what is the declared type of those three things?  The only possible answer would 
have to be the first one being sometype but the second and third being basetype, 
but this seems weird since I and J have the same value, and obviously I*1 has 
the same value as I, but... and what if you nest them and I is now a different 
variable I and not the outer variable I?

We really don't want to have to answer questions like that.  And we really don't 
want to make the compilers do complicated pattern-matching.  And (IMO) it looks 
really confusing to the reader too.

Cheers,
-- 
................................Malcolm Cohen, Nihon NAG, Tokyo. 




More information about the J3 mailing list