(j3.2006) Should character strings be interoperable with char arrays?

Aleksandar Donev donev1
Tue Jul 24 15:00:49 EDT 2007


On Tuesday 24 July 2007 09:36, Bill Long wrote:

> Not for the filename variable. ?You can supply a character variable with
> length > 1 as the actual argument (typically ?
> actual_file_name//C_NULL_CHAR).
Yes, this is what I do (I did not show that piece). The annoyance is not being 
able to do that for the varnames argument by virtue of not being able to do 
C_LOC on them by virtue of them not being interoperable. I can cheat and do 
C_LOC(string(1:1)) but not C_LOC(string).

> > and adding TARGET to all the arrays:
> Not for the cases of the pts and vardim arguments.
> ?A C programmer would be
> faced with basically the same actions.
All true, but it is worse for Fortran programmers. To C people this interface 
is not clumsy---there it is easy to construct and pass arrays of pointers 
once you have the arrays. In Fortran it requires making contiguous copies 
with the TARGET attribute and doing C_LOC. If one wants to avoid forcing the 
user to make such copies, one is stuck writing wrappers to try to make the 
interfaces more Fortran friendly. In this case this is not easy: I have to 
write a wrapper for a single variable (nvars=1), one for two variables 
(nvars=2), etc. It will not be a pretty interfaces for more than two 
variables.

I still believe that "pass by address" should be easier to do than C_LOC 
provides (requiring making contiguous copies with TARGET attribute). It is 
easy for the most common cases, but often one is forced to use TYPE(C_PTR) 
and C_LOC. I do not see a way how to write a user function that would help me 
pass by address easily: If I have to make a contiguous copy where is it going 
to be deallocated? For normal argument passing we have the compiler do all 
that for us.

Aleks




More information about the J3 mailing list