As much as possible, I've taken to solving Fortran/C interface problems
with a level of indirection. I like to write Fortran and C wrappers that:
- Return values only by output argument
- Do not pass strings between languages (int tags are better)
- Use macros to accomodate different name-mangling conventions
- Use macros to accomodate different type mappings
- (Optionally) Allow the C to pass scalar input arguments by value
When I have a high-level description of the interface available, I can
generate the relevant interface routines automagically, and I don't need
to worry about making a mistake in the macros. Otherwise, I'll write
the wrappers by hand. Either way, I prefer not to deal with complex
return arguments on interlanguage calls (which I never could get working
on HP, if I recall) or with strings of any sort.
David
Jason Riedy wrote:
And I write:
- 2) Complex results are returned in an extra argument.
- COMPLEX FUNCTION BAR (X)
- REAL X
- BAR = CMPLX(X, -1.0)
- END
- acts like
- void bar(float x, float _Complex *out)
- { *out = x - 1.0f * _Complex_I; }
I put the out argument on the wrong end; it's first in the
argument list.
Jason
|