Click here to Skip to main content
15,886,919 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: I like C more than I thought I would Pin
den2k8814-Sep-22 20:55
professionalden2k8814-Sep-22 20:55 
GeneralRe: I like C more than I thought I would Pin
David O'Neil14-Sep-22 21:16
professionalDavid O'Neil14-Sep-22 21:16 
GeneralRe: I like C more than I thought I would Pin
den2k8814-Sep-22 21:19
professionalden2k8814-Sep-22 21:19 
GeneralRe: I like C more than I thought I would Pin
Member 1330167915-Sep-22 0:00
Member 1330167915-Sep-22 0:00 
GeneralRe: I like C more than I thought I would Pin
David O'Neil15-Sep-22 6:21
professionalDavid O'Neil15-Sep-22 6:21 
GeneralRe: I like C more than I thought I would Pin
inlandchris114-Sep-22 21:34
inlandchris114-Sep-22 21:34 
GeneralRe: I like C more than I thought I would Pin
honey the codewitch14-Sep-22 22:14
mvahoney the codewitch14-Sep-22 22:14 
GeneralRe: I like C more than I thought I would Pin
giulicard14-Sep-22 21:57
giulicard14-Sep-22 21:57 
Another good argument for using C++ templates is its capability to "inject" code into algorithms. I mean that C is forced to use callbacks to expand the functionality of the algorithms: with C++ you can pass the "portion" of the algorithm that extends the functionality of the base algorithm as a template argument to a template parameter. Functors (or lambdas, they are the same beast) which has code declared inline, it is generally injected into the template of the base algorithm.

For example, the classic C library qsort algorithm, ignoring the fact that it forces you to play dangerously with casts to connect arguments to the callback function parameters, produces a function call for each comparison. If the algorithm (which is never a pure qsort but is a modified version, e.g. introsort) has to do with many elements and the compare function is inexpensive, it turns out that the biggest waste of time is in the invocation of the callback. In fact, especially when dealing with processors without caches or sophisticated branch prediction mechanisms, which is almost always the case with small MCUs, a function call can cost a lot.

This means that, apart from code bloating (which with modern MCUs is no longer a big problem since they have a lot of Flash), C++ is often faster than C, unless a C programmer writes everything by hand and doesn't use any library facility.

This gives the possibility to use the just-ready STL or Boost algorithms that do not need exceptions or dynamic allocation, customizing them efficiently. I want to remind all of you that usually the above code is written better than we could do and, in general, it is already debugged. And yes, using custom allocators and the placement-new operator, C++ can do what C does and many times it does even better: that is, C++, with a little care, can be happily used on small embedded systems.

Cheers
GeneralRe: I like C more than I thought I would Pin
honey the codewitch14-Sep-22 22:13
mvahoney the codewitch14-Sep-22 22:13 
GeneralRe: I like C more than I thought I would Pin
giulicard14-Sep-22 22:25
giulicard14-Sep-22 22:25 
GeneralRe: I like C more than I thought I would Pin
honey the codewitch14-Sep-22 23:04
mvahoney the codewitch14-Sep-22 23:04 
GeneralRe: I like C more than I thought I would Pin
Martin ISDN14-Sep-22 23:35
Martin ISDN14-Sep-22 23:35 
GeneralRe: I like C more than I thought I would Pin
honey the codewitch14-Sep-22 23:53
mvahoney the codewitch14-Sep-22 23:53 
GeneralRe: I like C more than I thought I would Pin
Martin ISDN15-Sep-22 2:22
Martin ISDN15-Sep-22 2:22 
GeneralRe: I like C more than I thought I would Pin
honey the codewitch14-Sep-22 23:58
mvahoney the codewitch14-Sep-22 23:58 
GeneralRe: I like C more than I thought I would Pin
Cpichols15-Sep-22 2:23
Cpichols15-Sep-22 2:23 
GeneralRe: I like C more than I thought I would Pin
Juan Pablo Reyes Altamirano15-Sep-22 4:43
Juan Pablo Reyes Altamirano15-Sep-22 4:43 
GeneralRe: I like C more than I thought I would Pin
sasadler15-Sep-22 6:14
sasadler15-Sep-22 6:14 
GeneralRe: I like C more than I thought I would Pin
honey the codewitch15-Sep-22 6:19
mvahoney the codewitch15-Sep-22 6:19 
GeneralRe: I like C more than I thought I would Pin
rjmoses17-Sep-22 23:39
professionalrjmoses17-Sep-22 23:39 
GeneralRe: I like C more than I thought I would Pin
honey the codewitch17-Sep-22 23:49
mvahoney the codewitch17-Sep-22 23:49 
GeneralRe: I like C more than I thought I would Pin
rjmoses19-Sep-22 0:29
professionalrjmoses19-Sep-22 0:29 
GeneralRe: I like C more than I thought I would Pin
Clive Hudson23-Sep-22 5:52
Clive Hudson23-Sep-22 5:52 
GeneralRe: I like C more than I thought I would Pin
honey the codewitch23-Sep-22 7:09
mvahoney the codewitch23-Sep-22 7:09 
AnswerPrograming gut feeling - ** Update! ** Pin
megaadam13-Sep-22 23:37
professionalmegaadam13-Sep-22 23:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.