Les Partages de Memiks
Tag cloud
Picture wall
Daily
RSS Feed
  • RSS Feed
  • Daily Feed
  • Weekly Feed
  • Monthly Feed
Filters

Links per page

  • 20 links
  • 50 links
  • 100 links

Filters

Untagged links
Calling C Code from C++ With 'extern "C"' - Simplify C++! https://arne-mertz.de/2018/10/calling-cpp-code-from-c-with-extern-c/
Tue Mar 17 16:25:46 2020 archive.org
QRCode

The correct solution

Since #include is a simple text replacement by the preprocessor, we can put the extern "C" declaration in our C++ code, where it belongs:

//main.cpp

extern "C" {
#include "foo.h"
}

int main() {
foo(22);
}

This way, everything inside the header, including the indirectly included declarations in other C headers, appear inside the extern "C" declaration.

cpp c++ c function call
4756 links, including 1670 private
Shaarli - The personal, minimalist, super-fast, database free, bookmarking service by the Shaarli community - Theme by kalvn