Home > On-Demand Archives > Talks >

C - The Language of Embedded

Colin Walls - Watch Now - EOC 2022 - Duration: 36:01

C - The Language of Embedded
Colin Walls
Although not designed for embedded software development, C is the most popular programming language for such application. We will consider why the language is so popular and conduct a brief "refresher" of C language functionality, with an emphasis on the benefits to the embedded developer.
M↓ MARKDOWN HELP
italicssurround text with
*asterisks*
boldsurround text with
**two asterisks**
hyperlink
[hyperlink](https://example.com)
or just a bare URL
code
surround text with
`backticks`
strikethroughsurround text with
~~two tilde characters~~
quote
prefix with
>

Otzen
Score: 0 | 3 years ago | 1 reply

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.
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 _init( ) function initialises this struct. This is essentially what happens in python and c++ it is just better hidden there.

ColinWallsSpeaker
Score: 0 | 3 years ago | no reply

Good points. Thanks.

MauricioFarina
Score: 0 | 3 years ago | 1 reply

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?

ColinWallsSpeaker
Score: 0 | 3 years ago | 1 reply

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!

Otzen
Score: 0 | 3 years ago | 1 reply

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");
ColinWallsSpeaker
Score: 0 | 3 years ago | no reply

That makes sense.

CaptainAubrey
Score: 0 | 3 years ago | no reply

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.

burak.seker
Score: 0 | 3 years ago | no reply

Great talk, thanks a lot

krasin
Score: 0 | 3 years ago | 1 reply

Thanks for the great overview of such a variety of concepts!

ColinWallsSpeaker
Score: 0 | 3 years ago | no reply

You?re welcome!

Phil_Kasiecki
Score: 0 | 3 years ago | 1 reply

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!

ColinWallsSpeaker
Score: 0 | 3 years ago | 1 reply

I did say "perhaps"! I think that some, but not many, embedded software developers might have a go at this.

Phil_Kasiecki
Score: 0 | 3 years ago | no reply

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!

glennk
Score: 0 | 3 years ago | 1 reply

Wow, I had no idea HDL syntax largely came from Ada, very interesting piece of history there!

ColinWallsSpeaker
Score: 0 | 3 years ago | 1 reply

Nothing new in the world!

glennk
Score: 0 | 3 years ago | no reply

Very true haha!

OUR SPONSORS

OUR PARTNERS