5 ms·
Much easier to link / load into other language binaries surely.
by emmelaich 2y ago
Much easier to link / load into other language binaries surely.
- adastra22 2y agoextern “C” works just fine.
- josefx 2y agoOnly if your entire API doesn't contain any C++.
- pjmlp 2y agoC is also C++, at least the C89 subset.
- procaryote 2y agoit actually isn't https://www.stroustrup.com/bs_faq.html#C-is-subset https://www.stroustrup.com/bs_faq.html#C-is-subset
- pjmlp 2y agoDo you usually post links without reading them? "In the strict mathematical sense, C isn't a subset of C++. There are programs that are valid C but not valid C++ and even a few ways of writing code that has a different meaning in C and C++. However, C++ supports every programming technique supported by C. Every C program can be written in essentially the same way in C++ with the same run-time and space efficiency. It is not uncommon to be able to convert tens of thousands of lines of ANSI C to C-style C++ in a few hours. Thus, C++ is as much a superset of ANSI C as ANSI C is a superset of K&R C and much as ISO C++ is a superset of C++ as it existed in 1985. Well written C tends to be legal C++ also. For example, every example in Kernighan & Ritchie: "The C Programming Language (2nd Edition)" is also a C++ program. "
- josefx 2y ago> For example, every example in Kernighan & Ritchie: "The C Programming Language (2nd Edition)" is also a C++ program. " That is rather dated, they do things like explicitly cast the void* pointer returned by malloc, but point out in the appendix that ANSI C dropped the cast requirement for pointer conversions involving void, C++ does not allow implicit void conversions to this day.
- pjmlp 2y ago> Well written C tends to be legal C++ also The "well written" remark is relevant. Many style guides will consider implicit void conversions not well written C. Naturally we are now on C23, and almost every C developer considers language extensions as being C, so whatever.
- deleted 2y ago[deleted]
- uecker 2y agoWell written idiomatic C is certainly not valid C++.
- pjmlp 2y agoDepends on the beholder, however it hardly matters on the days of C23, as mentioned.
- josefx 2y ago> The "well written" remark is relevant. So using casts that hid implicit int declarations for years is "well written"? > Many style guides will consider implicit void conversions not well written C. I could not find a "Many" guide, Linux Kernel and ffmpeg seem to advocate against pointless casts. > Naturally we are now on C23, So irrelevant to the creation time of ffmpeg and only applicable to intentionally non portable libraries.
- gjvc 2y ago
- p_l 2y agoOnly in certain limited cases, for example, can't have static class instances or anything else that could require calling before a call from "extern C" API. Also now you have to build enough of a C API to expose the features, extra annoying when you want the API to be fast so it better not involve extra level of indirections through marshalling (hello, KDE SMOKE) At some point you're either dealing with limited non-C++ API, or you might find yourself doing a lot of the work twice.