Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extern "C" function internally uses C++ class [duplicate]

Is this legal to do? I want to export a C function, but internally that function will use a C++ class.

extern "C" BOOL /*BOOL==int*/ Func()
{
   return someclass::getinstance()->Func(); // this is just bool tho
}
like image 220
Harry Avatar asked Oct 26 '14 14:10

Harry


Video Answer


1 Answers

This is perfectly legitimate. The purpose of extern "C" is to prevent Func() from getting its name mangled (decorated with type information) so that a C module can link to it using its plain name. C++ mangles names so that functions with the same name but different parameter lists can be resolved (function overloading).

like image 198
Amardeep AC9MF Avatar answered Sep 23 '22 15:09

Amardeep AC9MF