home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!sdd.hp.com!swrinde!news.dell.com!natinst.com!natinst.com!not-for-mail
- From: banshee@natinst.com (Jeff Kellam)
- Newsgroups: comp.lang.c++
- Subject: Re: How to call C++ functions in a C program?
- Date: 17 Dec 1992 11:41:09 -0600
- Organization: National Instruments, Austin, TX
- Lines: 43
- Distribution: world
- Message-ID: <1gqe3lINNs1v@eagle.natinst.com>
- References: <1gqbepINNt6s@function.mps.ohio-state.edu>
- NNTP-Posting-Host: eagle.natinst.com
-
- In article <1gqbepINNt6s@function.mps.ohio-state.edu> ren@function.mps.ohio-state.edu (Liming Ren) writes:
- >Hi , Merry chrismas , everybody!
- >
- >I hope this queston makes sense.
- >
- >I know we can call C functions inside a C++ program. Is there a way to
- >call a C++ function inside a C program? I tried to link a C program with
- >a C++ function as follows:
- >
- >cc f.o g.c
- >
- >Where f.o has a very simple C++ function inside and g.c is a simple C
- >program calling the function inside f.o. It dose not WORK!
- >
- >How to do this ? Please help!
- >
- >Many thanks!
-
- Basically, you can't.
-
- The C++ compiler mangles the name of the C++ function, thus the linker won't
- match it with the name you'd expect from C.
-
- If you know the name mangling scheme on your C++ compiler, you **might** be
- able to use that name. There are two limitations on this:
-
- 1. C prepends an underscore to function names. The mangling scheme your
- C++ compiler might not.
-
- 2. Both of the C++ compilers I use include in the mangled name characters
- like @ and $ which are not valid in a C function name.
-
- Of course, even if you get the name mangling taken care of, you'd still
- have to handle things like explicitly passing a pointer to the object and
- setting up virtual tables similar ugly things. Thus my original answer,
- you can't.
-
- Regards,
-
- jeff k
-
- --
- test
-