top | item 46512958

(no title)

Ragnarork | 1 month ago

> Is it easy to write a nice C interface for C++ that makes heavy use of templates, smart pointers, and move semantics?

If the interface itself has or leaks those features, no that's not easy indeed. But if those do not leak, then they can be used internally yes.

My point was not that it's easy to wrap a currently existing C++ library that has modern features in its interface in a C interface, especially post-C++11.

But that if you design something from the ground up, then it's rather easy (with a certain set of constraints). My bad for not conveying that better.

discuss

order

vrighter|1 month ago

Then the statement "Stuff can't interoperate with c++" is true. Nothing from c++ ever gets exposed. You have to explicitly write a C interface yourself, or avoid using c++ features (write C in c++) so everything looks like C in the first place and all you need is #ifdef __cplusplus extern "C" #endif. But then you're not writing c++ either.

Ragnarork|1 month ago

> Then the statement "Stuff can't interoperate with c++" is true

Where is that statement? The statement I reacted to (and with some caveats) was the following: "Libraries written in C++ or Java can generally only be used by applications written in the same language. It is difficult to get an application written in Haskell or Java to invoke a library written in C++."

Which in my opinion is not true for the reason I mentioned.

> Nothing from c++ ever gets exposed

Depends what's your definition for "getting exposed". If you mean "no C++ feature from the language gets exposed" then it's mostly true (you can still wrap certain things like allocators, though painful, but there's certain C++ features that have no real equivalent in some target languages indeed). But you can definitely expose the functionality of C++ code through a C interface.