What is best suited for writing a native library once and use it across multiple languages with language bindings?

StackOverflow https://stackoverflow.com/questions/14663854

문제

What language, C or C++, is best suited for writing a native library once and using it in different languages with language bindings (for example, using JNI or Ruby's C extensions), and why?

도움이 되었습니까?

해결책

C, because

  1. a program written in C++ can use a C library, the other way around is a whole lot trickier - any construct available in C++ but not in C cannot be exported to a C program, which risks to make your export complicated.
  2. A C library will have less dependencies. C++ libraries will quite often depend on libstdc++, which is that big that for example on embedded systems or more generally on systems low on resources it won't always be available.

다른 팁

You can write your library in C++ if you like as long as you provide extern "C" bindings/exports to it so the other runtimes can use it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top