[comp.lang.c] Borland C products and MS Fortran

sichermn@beach.csulb.edu (Jeff Sicherman) (05/16/91)

  Microsoft Fortran supports interlanguage calling to their C and Pascal
(and assembler, of course) through use of interface statements and
declaration attributes.

  Do the object module formats and calling conventions of Boralnd's C
products permit linking the object files in the same manner. I assume
this is equiavalent to asking if the Borland C compilers can
produce MS compatible object modules for linking together.

Jeff Sicherman

wew@naucse.cse.nau.edu (Bill Wilson) (05/17/91)

From article <1991May15.210252.12062@beach.csulb.edu>, by sichermn@beach.csulb.edu (Jeff Sicherman):
> 
>   Microsoft Fortran supports interlanguage calling to their C and Pascal
> (and assembler, of course) through use of interface statements and
> declaration attributes.
> 
>   Do the object module formats and calling conventions of Boralnd's C
> products permit linking the object files in the same manner. I assume
> this is equiavalent to asking if the Borland C compilers can
> produce MS compatible object modules for linking together.
>

There is no problem linking object files from these two compilers.
I have done it using arrays and large memory models.

The main thing that you need to know is the calling convention
for the various models.  The following examples should help:

The following is the C source that produces n random numbers:

#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>

void pascal inita(int far *n,int far *i);
void pascal sort(int far *n,int far *i);

main(argc,argv)
 int argc;
 char *argv[];
{
  long far *i,j,n;
  int now;

  if (argc-1==0){
	fprintf(stderr,"You must include the count on the command line.\n");
	exit(1);
  }
  n=atoi(argv[1]);
  printf("%ld bytes free\n",farcoreleft());
  i=(long *)farcalloc(n,sizeof(long));
  printf("%ld bytes free after I\n",farcoreleft());
  if (i==NULL){
    printf("Not enough room for allocation\n");
    farfree(i);
    exit(1);
  }
  srand(time(&now)%37);
  inita(&n,i);
  printf("After init:\n");
  for (j=0;j<n;j++) printf("%d ",i[j]);
  sort(&n,i);
  printf("\nAfter swap:\n");
  for (j=0;j<n;j++) printf("%d ",i[j]);
  farfree(i);
  printf("\n");
}


The two following routines are the Fortran source:


        INTERFACE TO INTEGER*2 FUNCTION RAND[C]
     +()
	END
	
	SUBROUTINE INITA(N[FAR],I[FAR])
	DIMENSION I(N)
	INTEGER*2 RAND
	DO 10 J=1,N
	  I(J)=RAND()
10	CONTINUE
	RETURN
	END



	SUBROUTINE SORT(N[FAR],I[FAR])
	DIMENSION I(N)
	DO 10 J=1,N
	  DO 20 K=J+1,N
	    IF(I(J).GT.I(K))THEN
	      ITMP=I(J)
	      I(J)=I(K)
	      I(K)=ITMP
	    ENDIF
20	  CONTINUE 
10	CONTINUE
	RETURN
	END
	
You can make a project file that lists the following:

f_ca.c
sort.obj
inita.obj

And from the IDE do a build all.  Should work without a problem in
the large memory model.

I have a document that I put together detailing all of this.  If you 
would like a copy, send me a note.

 
-- 
Let sleeping dragons lie........                    | The RoleMancer 
--------------------------------------------------------------------
Bill Wilson (wew@naucse.cse.nau.edu | ucc2wew@nauvm | wilson@nauvax)
Northern AZ Univ  Flagstaff, AZ 86011