Solved

can I CALL c++ METHODS FROM  A c PROGRAM ?

Posted on 2000-02-24
2
178 Views
Last Modified: 2010-04-02
HI,

can I CALL c++ METHODS FROM  A c PROGRAM ?

THANKS in advance.


0
Comment
Question by:tridev
  • 2
2 Comments
 
LVL 3

Expert Comment

by:Norbert
ID: 2553641
without any atribute - no
C++ mangles functionnames to code parametertype, number of parameters and so on to the function name. - That is the reason why function names looks so cryptic if the linker detects unresolved external functions.
But to switch of this mageling you can declare a function as
extern "C" Returntype Func(Parameter1Type P1 ,Parameter2Type P2,...,...)
in that case you only can use the features C provides.
Polimorph. functions are not possible for extern "C" declared functions. But
these functions now resides inside the C++ part they can call real C++ functons.
So you are able to write wrapper functions for the real C++ functions with full support to C++ functions
example:
Add(int Var1,int Var2, int* Result)
{
    *Result=Var1+Var2
}
Add(double Var1,double Var2, double* Result)
{
    *Result=Var1+Var2
}

extern "C" AddInt(int Var1,int Var2, int* Result)
{
    Add(Var1,Var2,Result);
}
extern "C" AddDouble(double Var1,double Var2, double* Result)
{
    Add(Var1,Var2,Result);
}
you can call AddInt or AddDouble fron C Code but you can't call Add directly from C

The example above makes no sense
because you can use + to do adding but it shows what I mean
0
 
LVL 3

Accepted Solution

by:
Norbert earned 10 total points
ID: 2553646
I forgot to switch from comment to answer.
My previous comment should be an answer
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now