Calling Pascal from C++ and Vice Versa

C

Chris Gordon-Smith

I am tying to call a Pascal function from C++, and vice versa.

Does anyone know how to do this, or where detailed information on this topic
can be found?

For the C++ to Pascal call I have tried declaring the Pascal function as:-

extern "C" void PASCALTESTFUNC1();

within my C++ code. However, the linker is giving me an unresolved
reference, even though I have a Pascal object file with a Pascal procedure
called PASCALTESTFUNC1.

extern "Pascal" doesn't compile.

Any comments or pointers will be appreciated.

I'm running on SuSE Linux 9.0, using GNU g++ for compiling C++, and the fpc
Free Pascal compiler for Pascal.
 
V

Victor Bazarov

Chris Gordon-Smith said:
I am tying to call a Pascal function from C++, and vice versa.

Does anyone know how to do this, or where detailed information on this topic
can be found?

Multi-language programming is compiler-specific. You should look in
your compiler manual about the availability and recommendations on how
to do that.
For the C++ to Pascal call I have tried declaring the Pascal function as:-

extern "C" void PASCALTESTFUNC1();

Why? Shouldn't it at least be

extern "Pascal"

??
within my C++ code. However, the linker is giving me an unresolved
reference, even though I have a Pascal object file with a Pascal procedure
called PASCALTESTFUNC1.

extern "Pascal" doesn't compile.

That means that your compiler doesn't support it, most likely.

Victor
 
R

Rob Williscroft

Chris Gordon-Smith wrote in
I am tying to call a Pascal function from C++, and vice versa.

Does anyone know how to do this, or where detailed information on this
topic can be found?

For the C++ to Pascal call I have tried declaring the Pascal function
as:-

extern "C" void PASCALTESTFUNC1();

within my C++ code. However, the linker is giving me an unresolved
reference, even though I have a Pascal object file with a Pascal
procedure called PASCALTESTFUNC1.

extern "Pascal" doesn't compile.

Any comments or pointers will be appreciated.

I'm running on SuSE Linux 9.0, using GNU g++ for compiling C++, and
the fpc Free Pascal compiler for Pascal.

You'll need to ask this in a forum thats about the tools your using.

The language doesn't define any way in which stuff compiled with
any other tool can be linked. Shuch things are only defined by the
tool vendors (implementors).

I'd start by asking in an fpc newsgroup/forum (if there is such a
thing), otherwise try a gcc newsgroup (news://gnu.gcc.help IIRC) or
a linux/SuSE newsgroup/forum.

HTH.

Rob.
 
N

Nick Hounsome

Chris Gordon-Smith said:
I am tying to call a Pascal function from C++, and vice versa.

Does anyone know how to do this, or where detailed information on this topic
can be found?

For the C++ to Pascal call I have tried declaring the Pascal function as:-

extern "C" void PASCALTESTFUNC1();

within my C++ code. However, the linker is giving me an unresolved
reference, even though I have a Pascal object file with a Pascal procedure
called PASCALTESTFUNC1.

extern "Pascal" doesn't compile.

You almost certainly want to look at your pascal compiler documentation
which will probably tell you how to link to C.
C is the common interface for many programming languages.
 
E

EventHelix.com

The parameter passing convention in pascal is different from C++.
In C++ code, the calling function is responsible for removing the function
parameters from the stack.

In Pascal code, the called function removed the parameters from the stack.

You might be able to write an assembly wrapper to fix this. I think
in the Windows environment you might get direct Pascal support as
some code in Windows/MS Office was originally written in Pascal.

Sandeep
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top