Solved

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

Posted on 2000-02-24
2
180 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

773 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