(j3.2006) A few constants from ISO_Fortran_env for C interop

Van Snyder Van.Snyder
Mon Oct 24 15:45:31 EDT 2011


On Mon, 2011-10-24 at 11:53 -0700, Lionel, Steve wrote:
> This doesn't make a lot of sense to me - the unit numbers can be used
> only from Fortran code, so the C code has to call Fortran anyway.

The output unit numbers desired by the caller are specified in a BIND(C)
structure.  In its Fortran declaration, the components that specify the
unit numbers are default initialized to OUTPUT_UNIT and ERROR_UNIT.  For
a C function calling the Fortran procedure, how do the members
corresponding to those components get meaningful values?

> How much of ISO_FORTRAN_ENV needs to be communicated to C?  KIND
> types?  IOSTAT values for EOR?

The only KIND type parameter values that are useful at run time are the
ones in ISO_C_BINDING, for a calling Fortran procedure to tell a called
C procedure what the type and kind of a TYPE(*) argument is (for
example, for HDF).  I've already suggested that there ought to be a
header file having those values, but Malcolm pointed out difficulties
with that suggestion.  It looks like in some cases there would need to
be several .h files, corresponding to different Fortran compiler
command-line options.

> A user function to return the values seems quite appropriate in this
> case.

That's one possibility.  Another is a little Fortran program that writes
a .h file with #defines for the values of interest to the program.  A
standard solution, if possible and reasonable, would be better.

> Steve
> 
> -----Original Message-----
> From: j3-bounces at j3-fortran.org [mailto:j3-bounces at j3-fortran.org] On Behalf Of Van Snyder
> Sent: Monday, October 24, 2011 2:44 PM
> To: j3
> Subject: (j3.2006) A few constants from ISO_Fortran_env for C interop
> 
> One of my colleagues is working on some software that needs to be told the Fortran I/O unit to which output should be written.
> 
> For two of the destinations, he wants the defaults to be OUTPUT_UNIT and ERROR_UNIT from ISO_Fortran_env.
> 
> The unit numbers are set in a structure.
> 
> He'd like to be able to use the code from C, so he's written a BIND(C) interface layer.
> 
> A question he asked, that I couldn't answer, is how the C program knows the values of OUTPUT_UNIT and ERROR_UNIT.
> 
> Should we add these values (and maybe a few more from ISO_Fortran_env) to ISO_Fortran_binding.h?
> 
> An alternative is to ask the C caller to call a BIND(C) Fortran procedure that returns the values.  That seems a bit like a kluge.
> 
> 
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://j3-fortran.org/mailman/listinfo/j3
> 
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://j3-fortran.org/mailman/listinfo/j3




More information about the J3 mailing list