[comp.lang.pascal] Need to call a large C procedure from Pascal.....

tcourtoi@jarthur.Claremont.EDU (Todd Courtois) (02/26/90)

I need a bit of help.  I have a main program written in Pascal, and
I have a large (20,000 line) C procedure that I would like to call
from the main program, instead of re-writing a similar procedure in
Pascal.

What do you all suggest?  Is there a way to include C source code in
a Pascal program and have it compile together?  I have access to several
different types of Pascal and C compilers, including TurboC/Pascal, 
QuickC, VAX_Pascal, etc...thus if you have a compiler-specific suggestion,
that might still be useful to me.

I have heard before that there are converters available which will convert
C to Pascal and Pascal to C, but for purposes of debugging I would prefer
not to convert the source code, since I already understand the C procedure
as written.

Thanks very much for any suggestions.  E-mail desired but not required. :)

--Todd Courtois   

tcourtoi@jarthur.claremont.edu  

james@abby.chem.ucla.edu (James Wilkinson) (02/26/90)

> I need a bit of help.  I have a main program written in Pascal, and
> I have a large (20,000 line) C procedure that I would like to call
> from the main program, instead of re-writing a similar procedure in
> Pascal.

This should be easy to do on the VAX.  Compile the C program as a module (ie.,
no main section), define the appropriate external routines in the pascal
program, call them, and you are happy.  You didn't say whether or not you want
to call the C code as a whole (which would mean you would need to make the C
code callable as a whole), so I'm assuming you only want to call subroutines
from the C code.  I know there are people at HMC that do this all the time.

JaW

James Wilkinson                            Phone: 1-213-206-5104
Department of Chemistry and Biochemistry     FAX: 1-213-206-5381
University of California, Los Angeles     BITNET: JAMES@UCLACH
405 Hilgard Avenue                      Internet: JAMES@ABBY.CHEM.UCLA.EDU
Los Angeles, California  90024-1569         SPAN: ABBY::JAMES or 5882::JAMES

bigelow@hpfcso.HP.COM (Jim Bigelow) (02/27/90)

> I need a bit of help.  I have a main program written in Pascal, and
> I have a large (20,000 line) C procedure that I would like to call
> from the main program, instead of re-writing a similar procedure in
> Pascal.

> What do you all suggest?

I suggest that you declare the C procedure as external and let the linker 
resolve the reference and link in the C routine.

Jim Bigelow
S300 Pascal
Colorado Language Lab
HP

merriman@ccavax.camb.com (02/28/90)

>> I have a main program written in Pascal, and
>> I have a large (20,000 line) C procedure that I would like to call
>> from the main program, instead of re-writing a similar procedure in
>> Pascal.

Three questions:

    1. What do the parameters to the C procedure look like?
    2. What does the C procedure return?
    3. Does the C procedure expect to share any global data with the main
       program?