PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Calling C functions from C++
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Calling C functions from C++

Réponse
 
LinkBack Outils de la discussion
Vieux 16/01/2008, 05h46   #1
sumaniitb@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Calling C functions from C++

We have a third party application coded in C++ which has hook for a
function that I need to implement. Is there a way such that I can
implement it in C and give my code as a library. I cannot use the
'extern C' since the application is built without my header file.

Example:

ThirdParty.cpp

extern void fun2();
fun1(){
....

fun2();

}



My code is supposed to implement fun2() in C.
  Réponse avec citation
Vieux 16/01/2008, 08h55   #2
dizzy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calling C functions from C++

sumaniitb@gmail.com wrote:

> We have a third party application coded in C++ which has hook for a
> function that I need to implement. Is there a way such that I can
> implement it in C and give my code as a library. I cannot use the
> 'extern C' since the application is built without my header file.
>
> Example:
>
> ThirdParty.cpp
>
> extern void fun2();
> fun1(){
> ...
>
> fun2();
>
> }
>
> My code is supposed to implement fun2() in C.


Because when ThirdParty.cpp code is compiled it will see it as a C++
function declaration, it will want to call a C++ function so no, you can't
compile fun2 in C (you can implement it in the C subset of C++ if you wish
but I assume you mean compile it with a C compiler). The only thing I can
think of is to have a translation layer, a fun2 in C++ that will call the
actual fun2 implementation from C code.

Something like:
translation.cpp

extern "C" void fun2_real();

void fun2()
{
fun2_real();
}

ccode.c

void fun2_real() { ... }

--
Dizzy

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h43.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08411 seconds with 10 queries