[OT] C vs C++

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Tue Aug 30 13:06:30 UTC 2022


On Monday, 29 August 2022 at 19:15:41 UTC, Dukc wrote:
> Why they do that, that's what I'm wondering. I can maybe 
> understand it for some firmware or device driver where 
> everything is so low-level anyway that C++ doesn't offer much 
> benefit but otherwise it's just mind-boggling.

* C is the only language that can be considered as a lingua 
franca and will remain in that position in the forseeable future. 
Far more programmers can use your library if you write it in C 
than in any other language.

* C++ does not have an OS mandated ABI, which most of the time is 
an advantage as  you can evolve and optimize more, but not for 
all use cases.

* You also loose a lot if you use C++ without a runtime. As a 
consequence of that it is much easier to convert a random C 
library so that it works without a runtime than to do the same 
with a random C++ library. So if you want your library to be 
useful in all contexts then you are better off writing it in C.

* You can easily convince yourself that the C-library you write 
for Python does not export symbols that Python does not require. 
It is easier to understand the consequences of using language 
features in C when writing plugins etc for other languages.

* C allows more typing hacks, more things are undefined behaviour 
in C++.

* "restrict" is standardized in C, compiler dependent in C++.

Does it make sense to pick C over C++ for language reasons? No… 
usually not. Are there other reasons? Yes.



More information about the Digitalmars-d mailing list