home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!ux1.cso.uiuc.edu!csrd.uiuc.edu!s4.csrd.uiuc.edu!schouten
- From: schouten@sp95.csrd.uiuc.edu (Dale Schouten)
- Subject: Re: How to call C++ functions in a C program?
- In-Reply-To: banshee@natinst.com's message of 17 Dec 1992 11:41:09 -0600
- Message-ID: <SCHOUTEN.92Dec17125550@sp95.csrd.uiuc.edu>
- Sender: news@csrd.uiuc.edu
- Organization: Center for Supercomputing R & D
- References: <1gqbepINNt6s@function.mps.ohio-state.edu>
- <1gqe3lINNs1v@eagle.natinst.com>
- Date: 17 Dec 92 12:55:50
- Lines: 30
-
- In article <1gqe3lINNs1v@eagle.natinst.com> banshee@natinst.com (Jeff Kellam) writes:
- > In article <1gqbepINNt6s@function.mps.ohio-state.edu> ren@function.mps.ohio-state.edu (Liming Ren) writes:
- >>I know we can call C functions inside a C++ program. Is there a way to
- >>call a C++ function inside a C program?
- >
- > Basically, you can't.
- Methinks thou doth protest too much.
-
- I'm not sure how standard it is, but with at least some compilers (read, `at
- least one', lest I get flamed for being presumptous) you can use an
- extern declaration (it's in The Book) and it will solve all your
- problems for you (that is to say, it'll take care of naming problems).
- Ofcourse you can't do the same things from C that you can in C++, like
- calling member functions directly and all that, but with a reasonable
- interface it shouldn't be difficult to do whatever you need.
- For example, for the compiler with which I am familiar, you say:
-
- extern "C" {
- int Cplusplus_function(int,char *);
- }
-
- and then in your c code you just call it by that name with those type
- of parameters and everythings hunky-dory.
-
- As I said, I don't know how standard it is, but check the docs on your
- compiler and there should be something somewhere.
-
- Good Luck!
- Dale Schouten
- schouten@uiuc.edu
-