(j3.2006) TYPE(*) and scalars

Rasmussen, Craig E rasmussn
Wed Mar 21 18:58:38 EDT 2012

On Mar 21, 2012, at 12:59 PM, Bill Long wrote:

> On 3/21/12 1:35 PM, Bader, Reinhold wrote:
>> Hello,
>> [...]
>>> It should be possible to work around this.  If the "known interface
>>> name" is foo, then
>>> interface foo
>>>   subroutine bar1 (x) bind(C, name="cbar")
>>>     type(*) :: x
>>>   end subroutine bar1
>>>   subroutine bar2 (x) bind(C, name="cbar")
>>>     type(*),dimension(*) :: x
>>>   end subroutine bar2
>>> end interface
>>> will work.  The specifics are distinguishable because of the rank
>>> distinction, independent of the types.  Since you can map both of them
>>> to the same C routine, there is no need to have extra C wrappers.  On
>>> the C side, the corresponding formal parameter is (void *), which is
>>> valid for either specific.
>> Unfortunately, this will not quite solve the problem, because it now is not possible any more
>> to process rank 2 and higher arrays - as soon as you put a DIMENSION(*) dummy into a generic
>> interface, exact rank matching of actual with dummy will be required. I guess one could add
>> interfaces with
>> type(*),dimension(1,*) :: x
>> type(*),dimension(1,1,*) :: x
> OK, but this is unrelated to whether TYPE(*) can be used without using assumed rank.  And all of these specifics can map to the same C function.  Admittedly, assumed rank is a simpler alternative.
> Cheers,
> Bill


I don't understand.  It seems that you are contradicting Reinhold as he says you can't use a generic interface (as you do in your foo example).  Also the fact that two different procedures have the same binding name seems problematic.  Suppose you try to implement bar1 and bar2 in Fortran, how does the C programmer have access  to either routine?  Especially since the symbol would have the same name and would lead to a conflict.

I assume it does too much damage to the standard to allow TYPE(*) to take both scalar and array actual arguments?  After all a scalar is now just an array of rank 0, yes (I can just hear Malcolm starting to wind up at this point so I'll not say any more :-)


More information about the J3 mailing list