Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inversion of Control or Dependency Injection -- anyone doing it in C?

See, for example, here

https://stackoverflow.com/questions/139299/difference-between-dependency-injection-di-inversion-of-control-ioc

to remind yourself what IoC and DI are.

The question and answer here

Is Inversion of Control specific to OO languages?

suggests that it does not require an OO language.

Now, my question: Anyone doing this in C?

I am asking because we write embedded C and are considering applying these methods, without changing our programming language.

like image 395
talkaboutquality Avatar asked Oct 16 '25 13:10

talkaboutquality


1 Answers

Doing it in C all the time. The hint is given in the answer from Azder in your second link:

"When you give a Windows API function a pointer to a callback function, you give them the control of calling your function with their own parameters."

From this point of view, the concept is already used in the Standard library for the functions qsort() and bsearch().

like image 157
Secure Avatar answered Oct 19 '25 03:10

Secure