Home > On-Demand Archives > Talks >
C - The Language of Embedded
Colin Walls - Watch Now - EOC 2022 - Duration: 36:01
Good points. Thanks.
Many places talk about decremental for loops being more efficient for ARM architecture. However, in many cases I end up having extra expressions like the i-1
in the example below:
//Incremental
for(i = 0 ; I < 10 ; ++i)
total += x[i];
//decremental
for(i = 10 ; i != 0 ; --i)
total += x[i-1];
Would that expression be optimized by the compiler even with -O0 optimization?
If there is any efficiency benefit from a decremental loop, it is marginal and totally out-weighed by the readability/understandability of an incremental loop. I cannot imagine that a compiler could optimize one into the other. I would be very impressed if it could do that!
I have seen compilers reverse into decrement, but only if the variable is only used by the for-loop itself. And not referenced by the code inside, examaple:
for(i = 0 ; I < 10 ; ++i)
printf("Hello\n");
That makes sense.
I would recommend skipping ahead to about 26 minutes where he starts talking about smart compilers.
The worst thing is the acoustics. He was in acoustically bright room and it sounded like he was in a barrel. Should have used a boom mike.
Great talk, thanks a lot
Thanks for the great overview of such a variety of concepts!
You?re welcome!
I had to chuckle at the slide saying that perhaps software engineers could do hardware design - having looked at some VHDL and gotten lost before long, I know that might be true for a few, but not many!
I did say "perhaps"! I think that some, but not many, embedded software developers might have a go at this.
You did, and you did convey, essentially, that it's not as easy as it might look to the untrained eye, which is exactly what I reacted as such because I've experienced it!
Wow, I had no idea HDL syntax largely came from Ada, very interesting piece of history there!
Nothing new in the world!
Very true haha!
You mention C++ and other OO variant of C.
One thing that developers should remember is that you do not need an OO language to do OO design, is doers makes it much easier sure, but you can still use a lot of the principles from OO when writting C.
i.e. I ussually create a .c file, more or less as I would create a class. All the public functions(methods) is included in the header file, and named with the module(class) prefixed. So a function "stop" of the class motor, will be named motor_stop(), resembling the c++ version where the method stop of calss motor would look like motor.stop)
All the private functions(methods) to the module(clas) is not included in the header and are declared static, removing them from the global namespace. private module(cllass) variables is likevise declared statid on file level, making them only accesible from within the module(class).
And then keeping a dicipline of only exposing what is needed in the header(interface), keeping the interface clean and clear.
This of course only gives you a resemblence of static clases, if you really need more instances of a class, I borrow from the python world, where the instance is passed as a parameter to all methods._init( ) function initialises this struct. This is essentially what happens in python and c++ it is just better hidden there.
in C I obtain this by defining a struct inside the .c file, and expose an inclomplete struct in the header, makes sure that the