Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Calling C functions in C++

&pagelevel(4)&pagelevel

C functions can be used in C++ without any problems, provided each C function is declared in C++ with an extern “C” directive and its complete prototype.

Example:

C source:

/* file = C_file.c */
int error_level;
void error(int number, char *text)
{
  printf("Error %d, Reason: %s\n", number, text);
}

C++ source:

// file = C++_file.C
extern "C" int error_level;
extern "C" void error(int, char *);
int main(void)
{
  error_level = 100;
  error(error_level, "TEST");
  return 0;
}

The C++ source contains externC” declarations for all the C identifiers used in it.