(j3.2006) A few constants from ISO_Fortran_env for C interop
Malcolm Cohen
malcolm
Mon Oct 24 21:53:13 EDT 2011
Firstly, I hope this is a suggestion for the next revision and nothing to do
with the interop TR.
Van Snyder claimed:
>Assignment statements instead, if their values (not their addresses) are
>needed in struct members.
Not generally true. (If you are in a context that requires a constant [e.g.
initialising a global] well then yes you need a constant, but if initialising a
local variable of a procedure that is not true - in C, "type VAR = VAL;" has the
same semantics as Fortran "type VAR; VAR = VAL".)
>Then on the C side I have
> typedef struct { ... int IO_unit ... } MyType;
>
> MyType myThing = { ... ????? ... };
>
>What do I put in place of ????? to set the IO_Unit member to a value
>that would cause the called Fortran procedure to use OUTPUT_UNIT or
>ERROR_UNIT?
Fortran_stdout or Fortran_stderr.
>I either need to have
>
> extern int Fortran_stdout, Fortran_stderr;
> myThing.IO_unit = Fortran_stdout; /* or Fortran_stderr */
Seems reasonable anyway, but not actually necessary.
>or call some Fortran routine
> initialize_MyType ( &myThing );
Seems reasonable anyway, but not actually necessary.
>or write a Fortran program that writes a .h file having #defines in it
>for INPUT_UNIT, OUTPUT_UNIT and ERROR_UNIT and #include that file to get
>the name to put in place of ????? (making sure to include compiling and
>running that program as part of "make")
Seems reasonable anyway, but not actually necessary.
There are many other ways to do this; for example, if the only choice is between
stderr and stdout (as in the motivating example), then a simple logical flag
"use stderr" would suffice. Or if the choice is stderr/stdout/a-specified-unit,
then a flag and an integer value would be more than adequate.
Given that there are multiple effective ways of skinning this cat, I see no gain
in adding yet another one that might save someone somewhere a couple of lines of
code someday. At significant cost to everyone else in the meantime.
There are lots of aspects of the Fortran computing environment that C does not
have direct access to, but which are trivial to write wrappers for
***using the existing C interop facilities***
This is one of those things. I really do not think it is the most useful.
Cheers,
--
................................Malcolm Cohen, Nihon NAG, Tokyo.
More information about the J3
mailing list