Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming a Microprocessor using C in Object Oriented Paradigm, is it Advisable?

Since C is commonly used in micro-controllers and it is possible to do object oriented programming in C, is it advisable to implement object oriented micro-controller programming using C? What are the pros and cons?

like image 328
LEMUEL ADANE Avatar asked Dec 13 '22 17:12

LEMUEL ADANE


2 Answers

My short answer is no. Microcontrollers are highly restricted when it comes to program code memory, execution speed, and RAM. Keeping things as simple as possible with C is advisable. C is not meant to be an object-oriented language. The most you should consider doing is using pointers and structs, but don't try faking polymorphism or anything fancy like that.

like image 170
Reinderien Avatar answered Jan 17 '23 18:01

Reinderien


As long as you do not need polymorpism it is ok to pass structs around. But as soon as you use polymorphism/virtual function and putting functions inside these structs it might become very cryptic.

It also depends what you need to do. For drivers you do not need OO, maybe for application. Keep in mind that microcontrolers are low whit RAM, any you will need to keep low RAM footprint all the time in any case.

If you do not plan to write more than 40k lines of application plain C is good enough and without fancy OO tricks.

like image 36
Luka Rahne Avatar answered Jan 17 '23 17:01

Luka Rahne