home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18137 < prev    next >
Encoding:
Text File  |  1992-12-17  |  1.8 KB  |  44 lines

  1. Newsgroups: comp.lang.c++
  2. 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
  3. From: schouten@sp95.csrd.uiuc.edu (Dale Schouten)
  4. Subject: Re: How to call C++ functions in a C program?
  5. In-Reply-To: banshee@natinst.com's message of 17 Dec 1992 11:41:09 -0600
  6. Message-ID: <SCHOUTEN.92Dec17125550@sp95.csrd.uiuc.edu>
  7. Sender: news@csrd.uiuc.edu
  8. Organization: Center for Supercomputing R & D
  9. References: <1gqbepINNt6s@function.mps.ohio-state.edu>
  10.     <1gqe3lINNs1v@eagle.natinst.com>
  11. Date: 17 Dec 92 12:55:50
  12. Lines: 30
  13.  
  14. In article <1gqe3lINNs1v@eagle.natinst.com> banshee@natinst.com (Jeff Kellam) writes:
  15. > In article <1gqbepINNt6s@function.mps.ohio-state.edu> ren@function.mps.ohio-state.edu (Liming Ren) writes:
  16. >>I know we can call C functions inside a C++ program. Is there a way to
  17. >>call a C++ function inside a C program?
  18. > Basically, you can't.
  19. Methinks thou doth protest too much.
  20.  
  21. I'm not sure how standard it is, but with at least some compilers (read, `at
  22. least one', lest I get flamed for being presumptous) you can use an
  23. extern declaration (it's in The Book) and it will solve all your
  24. problems for you (that is to say, it'll take care of naming problems).
  25. Ofcourse you can't do the same things from C that you can in C++, like
  26. calling member functions directly and all that, but with a reasonable
  27. interface it shouldn't be difficult to do whatever you need.
  28. For example, for the compiler with which I am familiar, you say:
  29.  
  30. extern "C" {
  31. int Cplusplus_function(int,char *);
  32. }
  33.  
  34. and then in your c code you just call it by that name with those type
  35. of parameters and everythings hunky-dory.
  36.  
  37. As I said, I don't know how standard it is, but check the docs on your
  38. compiler and there should be something somewhere.
  39.  
  40. Good Luck!
  41. Dale Schouten
  42. schouten@uiuc.edu
  43.