News for hackers. Stuff that matters.
Re:Type-erased generic functions for C: A modest non-proposal by jay-barronville on Thursday October 03, 2024 @07:44AM (#41729725)
> I mean, most of C just compiles as C++ and does the right thing.

In my experience, unless you’re strictly talking about header files (which I’m assuming you’re not), C code compiling via C++ compilers is usually hit or miss and highly dependent on the author of the C code having put in some effort into making sure the code actually compiles properly via a C++ compiler.

In the overwhelming majority of cases, what lots of folks do is just slap that `extern "C"` in between `#ifdef __cplusplus` and call it a day—that may work for most forward declarations in header files, but that’s absolutely not enough for most C source files.

By the way, a great example of C code that does this exceptionally well is Daan Leijen’s awesome mimalloc [0]—you compile via a C or C++ compiler and it simply just works. It’s been a while since I read the code, but when I did, I could immediately tell the code was written with that in mind.

[0]: https://github.com/microsoft/mimalloc

There are no comments on this comment yet.