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);
}
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);
}