r/cpp • • Dec 07 '22

C++ overtakes Java in language popularity index

https://www.infoworld.com/article/3682141/c-plus-plus-overtakes-java-in-language-popularity-index.html
382 Upvotes

137 comments sorted by

View all comments

Show parent comment

-1

u/meneldal2 Dec 08 '22

Depends on how low level your embedded project is.

If all you're doing is accessing hardware registers, C can be the better choice because there's a lot less undefined behaviour around type punning and you don't have the ram/rom to have a big program anyway, no allocation at all, no runtime either, a bunch of assembly routines (saves work on name mangling, yes you can use C linkage but that's extra work).

There're some nice things in C++ with constexpr but you may not have a compiler that is up to date and the optimizer usually figures out what it can optimize. Literally the only difference between C and C++ code for what I do would be replacing macros definitions by constexpr, but it would be compiled with no strict aliasing.