|
|
Subject:
Calling a member c++ function from a c file.
Category: Computers > Programming Asked by: frankooo-ga List Price: $5.00 |
Posted:
25 Nov 2003 23:40 PST
Expires: 25 Dec 2003 23:40 PST Question ID: 280715 |
I have a Borland Builder C++ application that needs to communicate back and forth with c files. It's easy enough to make c function calls from C++ using extern, but I need to know how to easily do things in the other direction. For example, my c function has a need to set a particular serial port pin which I need for it to be done through my C++ AsynchPro class member object. I've done some reading, and it's not that hard to have a c function call class static functions or access static variables, but I need for it to access class member variables and/or functions. Right now I'm faking it out by having the C file call a c++ static function which sets a static variable indicating to a timing loop in the c++ class that something has changed, which then goes ahead and changes member objects/variables - in effect it's a message system. However, this is growing bigger and I want to know how to hook these calls in without a timer. I need a nicer solution. And no, I can't just compile it all in either c or c++, i need to do it in this specific way. Thanks! | |
| |
|
|
Subject:
Re: Calling a member c++ function from a c file.
Answered By: mathtalk-ga on 26 Nov 2003 10:13 PST Rated: |
Hi, frankooo-ga: Well, just for sport you might want to use the "create cross-reference listing" in the C++ compiler for one of the modules. Of course this requires that you have the source code for it, which is one limitation. Then you identify the mangled name for the member functions you need, which are then the forms you want to use from your C code. Playing with the linker, rather than letting the compiler/IDE tool call it for you, is not much fun, but in days gone by there was more of a collision between existing C code and new C++ stuff. regards, mathtalk-ga |
frankooo-ga
rated this answer:
Thanks! I'll close it now. Anyone who has time to provide a very brief ansert to a couple very quick q, much appreciated: In Borland Builder, Project->Options, there is a "Tasm" page which has an option to "generate listing", including "cross reference", and "symbol tables information". I assume cross ref will give me what I need. Is this listing typically generated inside the obj file? If so, how do I view it? How precisely would I call a function once I know the mangled name? Please provide a very quick example? Finally, can I pass parameters, eg char, boolean in to mangled functions? Thanks again |
|
Subject:
Re: Calling a member c++ function from a c file.
From: yosarian-ga on 27 Nov 2003 01:04 PST |
Hi frankoo-ga. The C++ faq lite is an excellent resource for this kind of things. Here is a link to a similar question: http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html#faq-32.6 HTH yosarian-ga |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |