Search code examples
cfortranopenvmsvax

OpenVMS (VAX) Fortran function returning a character*(*) to C


A OpenVMS (VAX) FORTRAN subroutine can be passed a character*(*):

subroutine forsub (in)
character*(*) in
type *, in
return
end

from a C function:

#include<stdio.h>
#include <descrip.h>
extern void forsub();
main()
{
    auto $DESCRIPTOR(in_string, "VMS pass from c to fortran.");
    forsub(&in_string);
}

How is the OpenVMS (VAX) FORTRAN function that returns a character*(*):

character*(*) function forfunc (in)
character*(*) in
forfunc = in
return
end

handled in the C code:

#include<stdio.h>
#include <descrip.h>
extern ?????? forfunc();
main()
{
    auto $DESCRIPTOR(in_string, "VMS fortran function return to c.");
    ??????? = forfunc(&in_string);
}
  • OpenVMS V6.2
  • Digital Fortran 77 V6.5-188
  • DEC C V6.0-001

Solution

  • Example 3-5 in this (old?) C User's Guide probably explains how to do this: you need the already mentioned hidden argument. An example would be:

    #include <stdio.h>
    #include <descrip.h>
    extern void forfunc();
    main()
    {
        auto $DESCRIPTOR(in_string, "VMS fortran function return to c.");
        char buffer[64];
        struct dsc$descriptor_s out_string = {
            sizeof buffer, DSC$K_DTYPE_T, DSC$K_CLASS_S, buffer};
        forfunc (&out_string, &in_string);
        printf ("%.*s\n", out_string.dsc$w_length, out_string.dsc$a_pointer);
    }