extern "C"

extern "C" int app_init(int argc, char** argv){

can u explain it?
extern "C" is meant to be recognized by a C++ compiler and to notify the compiler that the noted function is (or to be) compiled in C style.

Take an example, if you are working on a C++ project but it also deals with some existing C functions/libraries.
You want to wrap them in a C++ module or compile them with other C++ objects without any C++ compiler errors, then you would declare the C function prototypes in an extern "C" block to notify the compiler that they would be compiled along with other C++ functions into one module.

For example:



/*check if the compiler is of C++*/
#ifdef __cplusplus
extern "C" {
int myOtherCfunc(int arg1, int arg2); /* a C function */

void myCppFunction1(); /* C++ function */
void myCppFunction2(); /* C++ function */

/*check if the compiler is of C++ */
#ifdef __cplusplus


Now all three functions are comiled into one module by C++ compiler.

Hope you got it. Good luck :)
Topic archived. No new replies allowed.