As I read Naomi's question, she wants to write a C function that would
have a formal parameter of the same C type as a Fortran actual parameter
declared using selected_int_kind, and that she would like to be able to
ask the compiler to choose the C type using the same sorts of things you
can tell the Fortran compiler to consider in a reference to
selected_int_kind.
If that is her question, I think the answer is "no."
Maybe one could write a C macro equivalent to selected_int_kind, but
AFAIK the C standard doesn't define one.
As Tim Prince suggested, you could write a Fortran program that uses
selected_int_kind to generate a .h file with such a macro in it.
On Tue, 2010-12-07 at 15:54 -0800, Bill Long wrote:
> On 12/7/10 2:57 PM, Dan Nagle wrote:
> > Hi,
> >
> > To portably call a C function with an int argument,
> > use one of the kind parameters in the iso_c_binding module.
>
> To fill in a few more details... The issue is that C uses different
> names for the various kinds of integers, and the need is to make sure
> that the variable you supply as an argument in the Fortran CALL is the
> same kind as the C function is expecting. The design of the C
> interoperability feature in Fortran is to allow this to be done in a
> portable fashion.
>
> If the C function is expecting an 'int *' argument, then in the Fortran
> caller,
>
> use,intrinsic :: iso_c_binding
> integer(c_int) :: N ! C_INT is defined in the module
>
> ...
>
> call c_func(N)
>
>
> > If your compiler supports Interoperability with C,
> > it should supply such a module.
>
> By this time, most compilers do support this capability. There are
> several other aspects of C interoperability, including specifying an
> interface for the C function that allows for things like a mixed-case
> name for the function, and C-compatible pass-by-value semantics. C
> interoperability was one of the most popular Fortran 2003 features.
>
> Cheers,
> Bill
>
> >
> > On Dec 7, 2010, at 3:47 PM, Greenberg, Naomi wrote:
> >
> >> Does anyone know if there is a C equivalent of selected_int_kind? I would like to write portable code for use with many compilers/machine architectures, but I have a Fortran routine that calls a C function and passes an integer variable to it that I want to declare using selected_int_kind and specifying a range.
> >>
> >> Thank you,
> >>
> >> Naomi Greenberg
> >> Member of the Research Staff
> >> Riverside Research Institute
> >>
> >> (212) 502-1718 (ph)
> >> (212) 502-1729 (fax)
> >> [log in to unmask]
> >>
> >
>
|