Skip to main content
1 of 17
Basile Starynkevitch
  • 32.7k
  • 6
  • 87
  • 131

You cannot do that because some languages implementations could have an ABI different and incompatible with the C one.

On current systems, C is very common and most (but not all) language implementations have an ABI and calling conventions compatible with the one from C. Notice that it is a property of the implementation (your C compiler and your operating system), not of the programming language.

If using C++, beware of name mangling and of exception handling. (e.g. C longjmp is not friendly with C++ exceptions). Dynamic loading facilities like dlopen and dlsym are relevant to name mangling. So prefer an API using extern "C" functions.

Memory management (notably with garbage collection) is also an issue.

Basile Starynkevitch
  • 32.7k
  • 6
  • 87
  • 131