home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!decwrl!sdd.hp.com!swrinde!ringer!mlevis
- From: mlevis@ringer.cs.utsa.edu (Mike Levis)
- Newsgroups: alt.msdos.programmer
- Subject: Re: Calling ASM from BC++
- Message-ID: <1992Aug25.232741.15553@ringer.cs.utsa.edu>
- Date: 25 Aug 92 23:27:41 GMT
- References: <1992Aug24.204813.16175@schunix.uucp>
- Organization: University of Texas at San Antonio
- Lines: 69
-
- In article <1992Aug24.204813.16175@schunix.uucp> sonix@schunix.uucp (Duane Morin) writes:
- >I'm trying to call an assembly routine from some standard Borland C++ (2.0)
- >code. Here's what I've got (in the C++):
- >
- >extern foo_bar3(int G, int P);
- >.
- >.
- >.
- >foo_bar3(i, x);
- >
- >And, in the ASM module, I've got:
- >
- > PUBLIC _foo_bar3
- >PROC foo_bar3 FAR
- > ARGS G:word, P:word
- > .
- > .
- > .
- >
- >But C++ fails to recognize the foo_bar3 function. Keeps telling me
- >unrecognized symbol. As if it doesn't get the connection, because I'm not
- >declaring the two int parameters in the actual definition in the ASM file.
- >I got the syntax for doing this out of an "Interfacing C and ASM" book, so
- >I assume that maybe I need to do somethng else to make this work in C++.
-
- C++ uses name mangling. Under C, the compiler pre-pends an underline
- to the the function name, and writes it to the .obj file for the linker.
- Under C++, the compiler also appends extra characters to the function
- name. This is name mangling.
-
- These extra characters are based on the parameters of the function.
- This is why you can overload functions in C++ (as long as the parameter
- types differ), where as in C you must specify a unique function name.
-
- As the Borland manuals state, the algorithm that Borland C++ uses
- to mangle names is undocumented. In other words, C++ compilers
- use different techniques for mangling names.
-
- >Any suggestions? Minor errors in my transcription of the code might be
- >typos of mine just in this post, as I put that code in there from memory
- >and may have slipped up (ARG vs ARGS or something). Any help, however,
- >still appreciated.
-
- Declare your assembler function with a C interface rather than a
- C++ interface. Change
-
- extern foo_bar3 (int, int);
-
- to
-
- extern "C" {
- foo_bar3 (int, int);
- }
-
- There are other ways to call assembler functions from C++. These
- other ways are documented in the Borland Manuals, such as chapter
- 5, "Interfacing Turbo Assembler with Borland C++".
-
- >Thank you,
- > Duane Morin
- > Walker Sonix, Inc.
- > sonix@schunix.uucp
-
-
- --
- ==== Mike Levis mlevis@ringer.cs.utsa.edu ====
- :: ftp ftp.cs.widener.edu (147.31.254.132) :: .--.
- :: for ``The Simpsons'' information. Get :: (OS/2)
- :::: ``Simpsons'' FAQL in dir /pub/simpsons :::: ~--~
-