[comp.lang.pascal] TC++ <-> TP 6.0 Mixed Language Development

defaria@hpcupt3.cup.hp.com (Andy DeFaria) (04/04/91)

Is it  possible to  call Turbo  Pascal  6.0  functions from Turbo C++?  The
manual doesn't say so but there is this conspicuous keyword called "pascal"
that can be specified on data declarations  (gee, what does  it do?) and on
function declarations.  The manual says that this merely imposes a "pascal"
calling convention  and then says  something about,  sorry  but  I left the
manual at home, the fact that this does not  mean that you can  call pascal
routines but just that the "pascal" calling convention  is supported.  This
is all in, I believe,  Chapter  6 of  the  programmers guide.  The rest  of
Chapter 6 discusses interfacing with assembler.

I  can't believe that Borland would  choose the   keyword "pascal" to  mean
"interface  to   assembler".  Gee, wouldn't   a  better keyword  have  been
"assembler"?

I also can't believe that Borland's Turbo C++ product would not be able to
interface cleanly and easily to Borland own  Turbo Pascal product and given
the fact that  there is probably a  large  amount of perfectly   good Turbo
Pascal code out there  that could be migrated to   Turbo C++  a piece  at a
time, I   would think  that somebody   has   a workaround to this   obivous
oversight on Borlands part.

Does anybody know more about this?

Oh, and how would you go the other way around (TP 6.0 -> TC++)?

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (04/05/91)

In article <45670006@hpcupt3.cup.hp.com> defaria@hpcupt3.cup.hp.com (Andy DeFaria) writes:
>Is it  possible to  call Turbo  Pascal  6.0  functions from Turbo C++?  

Probably possible, but not really practical.  The linker that TC++ uses
(TLINK?) doesn't understand the object format (.TPU) that TP uses.  The
only way to do it would be to get around this limitation; it's not easy.

>I  can't believe that Borland would  choose the   keyword "pascal" to  mean
>"interface  to   assembler".  Gee, wouldn't   a  better keyword  have  been
>"assembler"?

I think Pascal is something of a standard to define the convention that
parameters are pushed onto the stack starting on the left, and that the
routine that gets called is responsible for removing them.  Assembler 
doesn't have conventions - you can do whatever you like there.

>I also can't believe that Borland's Turbo C++ product would not be able to
>interface cleanly and easily to Borland own  Turbo Pascal product and given
>the fact that  there is probably a  large  amount of perfectly   good Turbo
>Pascal code out there  that could be migrated to   Turbo C++  a piece  at a
>time, I   would think  that somebody   has   a workaround to this   obivous
>oversight on Borlands part.

I don't know of any workarounds.

>
>Does anybody know more about this?
>
>Oh, and how would you go the other way around (TP 6.0 -> TC++)?

The other way is a little easier, because the TP linker (built in to TURBO
or TPC) has a limited understanding of .OBJ files.  There are tons of 
restrictions though - it doesn't even understand .LIB files.  

In my experience, it's much less headache to just go ahead and translate
the code than it is to mix languages.

Duncan Murdoch
   dmurdoch@watstat.waterloo.edu

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (04/05/91)

Just after I wrote the previous message, I opened a letter from Borland
advertising TP for Windows.  To quote:

"You can write Windows Dynamic Link Libraries (DLLs) callable from Borland
C++, or other languages that support DLLs.  Your Pascal program can also
call DLLs written in other languages."

So it looks as though it's easier to write mixed language programs under
Windows than under DOS.

Duncan Murdoch
dmurdoch@watstat.waterloo.edu 

lamouche@aurora.physics.utoronto.ca (Guy Lamouche) (04/06/91)

In article <45670006@hpcupt3.cup.hp.com> defaria@hpcupt3.cup.hp.com (Andy DeFaria) writes:
>Is it  possible to  call Turbo  Pascal  6.0  functions from Turbo C++?  The

	If you look on the distribution disks, you will find examples of
	this in CTOPAS.C and CTOPAS.PAS. But even if this is possible,
	you will encounter problems because Turbo C makes calls to
	internal functions that you would have to recompiles with  the
	pascal calling convention ( you would need the runtime library
	C source code).
	If you need some C built-in routine, forget it.
					 Guy LAmouche
					 penguin.physics.utoronto.ca