Fortran Callable C Interface

Fortran Callable C Interface

Post by Mike Rutsch » Wed, 09 Dec 1992 10:47:18



Hi.

I need some help with a fortran callable C interface.  The C interface
looks as follows:

extern int
MhGetMsgVaList (int message_code,
                size_t max_message_size,
                char * message_p,
                ...)

I have two main problems/concerns:
   1) With IBM RS/6000 AIX Fortran you can specify %val or %ref
      to pass by value or by reference - %ref also prevents the default
      behavior of placing the length of the string at the end of the
      parameter.

      How portable is %val or %ref?  The code being written does not
      have to be highly portable, but it most likely will be ported to
      HP/UX, Solaris, Irix, OSF/1.

      I can get around this "problem" by have a special Fortran interface
      where every parameter is a pointer to <type>.

   2) The internal implementation calls vsprintf and by using the
      above %val/%ref I have get short,int,* char, but have but
      unable to get floats to work.  The only way I have managed passing
      floats is to explicitly specify as follows:

typedef
union param
{
    char c;
    short s;
    int i;
    long l;
    float f;

Quote:} param;

int
MhGetMsgVaList (int message_code,
                size_t max_message_size,
                char * message_p,
                param *p1,
                param *p2,
                param *p3,
                param *p4,
                param *p5,
                param *p6,
                param *p7,
                param *p8,
                param *p9)

{
    int i;
    float f;

    i = (*p2).i;
    f = (*p3).f;

Quote:}

In reality, I would scan the message format (retrieved using the
message_code parameter) to determine the type of each parameter.  
This has the drawback of being much more difficult to implement, plus I
was only able to support specifying either float or double (not both, which
is can be done using variable list arguments for C function calls - I assume
that this might be because the parameters are always cast to a double?).
I have some problems with specifying a single byte integer, but that is
the least of my worries(until I resolve all my other problems).

What I don't understand is why I can pass Fortran integers and strings
through variable list parameters, but I when I try floats vsprintf always
outputs 0.0.

Any help would be greatly appreciated!!

--

 
 
 

1. Fortran-callable date function

A user here is porting some VMS Fortran code to AIX.  Everything works
except he hasn't found a replacement for the date function.  He's
tried writing one in C using localtime, but gets errors about
something to do with timezones.

Anyway, before I dive in and fix it myself I wanted to see if anyone
else had had and fixed the same problem or knows of standard AIX
Fortran date function.

Thanks in advance.

--

Martin Marietta Energy Systems    all the money they need and the Air Force
Workstation Support               has to hold a bake sale to buy a new bomber.

2. RFI: NIS+ in large networks

3. Fortran callable graphics library

4. Gamma correction in XFree86

5. C/fortran interface

6. Help NEEDED with upgrading GCC

7. Fortran - C interface problem

8. Imagine 128 Series II 8MB VRAM

9. cfortran.h: Interfacing C and FORTRAN

10. interprocess communication (interface for FORTRAN)

11. Fortran and C Compiler for Linux (Ex Apollo Domain Fortran)

12. EDC Fortran or MicroWay NDP Fortran run on Linux?

13. Fortran Debugging trouble + comercial Fortran