Home > On-Demand Archives > Q&A Sessions >

Live Q&A - C - The Language of Embedded

Colin Walls - Watch Now - EOC 2022 - Duration: 20:25

Live Q&A - C - The Language of Embedded
Colin Walls
Live Q&A with Colin Walls for the talk titled C - The Language of Embedded
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!

09:44:12 From  Eric L  to  Everyone:
	In your presentation you said that you thought that C++ might be better. Could you expand on that.
09:47:12 From  Gillian Minnehan  to  Everyone:
	Colin, you mentioned that misuse of pointers is a big pitfall in C. Are there other major pitfalls that you see a lot in the projects you work on? If so, do have suggestions on how to avoid them?
09:47:19 From  Gonzalo  to  Everyone:
	do you see a difficulty or care to be taken when a project combines modules written in C with others done in C++?
09:48:48 From  Mauricio Farina  to  Everyone:
	Do you consider good practice to declare #define values inside functions for making simpler and more readable expressions?
09:48:51 From  Nathan O.  to  Everyone:
	Do you have any opinion on the LLVM/clang vs GCC fight ? And on the open source compiler vs proprietary compilers (IAR / Keil) topic ?
09:50:05 From  Gillian Minnehan  to  Everyone:
	Thank you!
09:51:40 From  Phillip Kajubi  to  Everyone:
	You say developers spend more time debugging than programming, is this a good thing, and would you consider it a unpreventable result of modern language design
09:52:53 From  Mauricio Farina  to  Everyone:
	Perfect, thank you
09:55:03 From  Hatim Jamali  to  Everyone:
	In your example of explaining variables, we should sometimes add another variable (DeviceError) maybe we can run out of memory in some cases, what is your recommendation in those cases? 
09:55:26 From  ÖmerHeybeli  to  Everyone:
	Would you recommend doing a detailed design (graphically) before writing C code for Embedded Systems?
09:57:50 From  Rick D  to  Everyone:
	What is your opinion about using assert() functions in released code?
09:58:06 From  Phillip Kajubi  to  Everyone:
	Fantastic, thanks!
09:58:37 From  Nathan O.  to  Everyone:
	Do you often find yourself checking the output of your compilers ? I tend to use godbolt.org when I have some doubt
09:59:17 From  ÖmerHeybeli  to  Everyone:
	thanks
10:00:11 From  Mauricio Farina  to  Everyone:
	What is your opinion about using dynamic memory for embedded code?
10:00:50 From  Nathan O.  to  Everyone:
	Thanks
10:01:04 From  Eric L  to  Everyone:
	Thanks!
10:01:12 From  Rick D  to  Everyone:
	Thanks for the informstive session :-)
10:01:25 From  Erick Souza  to  Everyone:
	Thanks (y)

OUR SPONSORS

OUR PARTNERS