• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

How are some pascal functions called in c++

I have an ansi version of C++ and looking for the names of
some functions which I know they're name in pascal but not
in C++.
The functions are :
  GetIntVec/SetIntVec
  Port[] array.
 
0
Phoenix020397
Asked:
Phoenix020397
  • 4
1 Solution
 
white wolfCommented:
It's hard to answer your question directly because I don't know your compiler settings, etc.  But I'll try to help out...

First off, to make sure they're compatible, you should tell both C++ and Pascal compilers to use the same "calling convention".
It should be under the compiler options menu or something.
This convention (either "C" or "Pascal") tells the compiler if the parent function is responsible for cleaning up the stack or not...

Now, you have to check both compiler settings again to check if they're automatically prefixing an underscore (or other) character to the name of subroutines.  This should be under the linker menu I think.  If your Pascal compiler doesn't have this "option", you can set the C compiler option to "NO, don't put an underscore" (the C compilers are generally more configurable in this area...)

Also, don't forget to:
1. declare (in the C files) publically the "equivalent" function prototypes of the Pascal procedures/functions it uses.

2. declare (in the interface or public section of Pascal files) the equivalent prototypes of C functions it uses.

To make sure that naming conventions are ok, you can tell both compilers (actually the linkers) to produce detailed MAP files.  These .MAP files produce a listing of the ACTUAL function name and (relative) addresses.  Check the names.

Now, more specific to your problem, remember that a pascal array can be declared as a (char *x) in C/C++.  You may have to play with it if one of your linkers barfs out a "fatal linker error", but otherwise compiles the code.  This fatal error is a sign that the linker can't find the declared function, and can be caused by 3 problems:
1. The function just doesn't exist in any .OBJ file
(that's cause you didn't write it at all!)
2. There's a "parameter type" mis-match.  This is usually the programmer's fault by declaring the function as taking, say, an integer, when the actual code specifies a string (char*), say.
3. the underscore **** is not at the same setting and the (dumb!) linker can't find the function names because one is called, say GetIntVect(?) and the other is _GetIntVect(?).
(the map file will tell you what the actual name is, so check it)

Hope this helps. Also, check out my page for extra info.
I have a doc (written by me) about interfacing pascal and/or C to assembly, that may provide extra details and insight.
Good luck dude!
0
 
white wolfCommented:
0
 
Phoenix020397Author Commented:
Those aren't procedures I built in pascal, they are in the DOS unit. There should be such functions in C++ too, but I don't know how to find them.
0
 
white wolfCommented:
You're kidding, right?  I wrote all that for nothing?!?
OK, for getting/setting interrupt vectors, use
setvect() and getvect() and for port operations, use
inport() (write an "int") and inportb() (write a byte);
outport() and outportb() are the ouput guys.
All are in dos.h...

0
 
white wolfCommented:
oops...  use inport to read (not write!!!)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now