Solved

How are some pascal functions called in c++

Posted on 1997-03-28
5
434 Views
Last Modified: 2008-03-03
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
Comment
Question by:Phoenix020397
  • 4
5 Comments
 
LVL 1

Accepted Solution

by:
white wolf earned 50 total points
ID: 1162502
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
 
LVL 1

Expert Comment

by:white wolf
ID: 1162503
0
 

Author Comment

by:Phoenix020397
ID: 1162504
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
 
LVL 1

Expert Comment

by:white wolf
ID: 1162505
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
 
LVL 1

Expert Comment

by:white wolf
ID: 1162506
oops...  use inport to read (not write!!!)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now