Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In your example, of interfacing with Python, yes I would usually go for C because to interact with CPython needs a C ABI in the end. C++ requires another tool to get there (pybind, swig, etc).


but pybind11 makes interop so much more trivial between C++ and python. passing std::vector, std::string, custom types, etc... it all just works and with much less errors possible than the C Python API. Why would you subject yourself to it ?


Pybind11 is for "C++11" -- I assume there's no special magic in later revisions that would cause anything to silently fail (i.e. fail at runtime)?


Works just fine here with c++20. it even automatically converts std::variant and std::optional


    extern "C" {
       // my C++ code

    }
Big deal.


Problem is, not many C++ libraries would care to do this in the first place.


The point was writing a library specially to be called from Python via the C ABI.

By the way, clang and Visual C runtime libraries are actually implemented in C++ with extern "C".




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: