🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #1486

Inversion-of-control and dependency-injection in C

#1486
From: Ross Finlayson
Date: Thu, 12 Nov 2026 17:41
46 lines
3858 bytes
Hello, dear C experts, I'm hoping you can tell me a story about
modularity and composability, about the concerns of inversion-of-control
and dependency-injection in C, basically about wiring
test-time and run-time targets, for example about conditional-includes
and various build-targets, probably mostly about function pointers.

A usual account for example might recount component frameworks,
like COM or XPCOM for example, about the concepts of components,
vis-a-vis, modularity and composability, and, satisfaction of
dependencies, vis-a-vis IPC and RPC, abstraction layers often enough,
then about adapters to dependencies, or as for resources, that
it's a bunch of makefiles with various accounts of conditional includes
and build targets about static and dynamic linking and the toolchain,
with regards to test-harness and runtime-framework and about
metaprogramming when making code generation and boilerplate and so on.


Defining an interface or layer is often enough about groups of functions
associated with context-structs to make for lifecycles
of what result alike the pure virtual or abstract or interfaces
in reference to languages like C++, about families of functions
according to the types of their signatures, then as with regards
to componentry rather generally in value-types and interface-types
like "variant" and "queryInterface()", about components that implement
multiple interfaces vis-a-vis mostly about "constructing the
object-graph" what makes for separation-of-concerns and composability,
is mostly about modularity and composability.

Then considerations of modularity as for library design affect to
reflect on how to indicate responsibilities of ownership in resources,
for example to hide contract & behavior of resources acquire/release.

What I'm figuring is that basically there is a flat name-space of
functions, there are .h and .c files (and may include "portable
assembler"), and there is the compiler-toolchain, and make or
build-scripts. Since there are only functions then dependencies their
references would basically live in structs (in structs, in structs, ...,
of function pointers), much like languages with classes and their
instances objects and subclassing overriding behavior keeping in
contract, about how to define "runtime-module" vis-a-vis "source module"
(.o files after compilation-units), about conditional-includes
and conditional-builds vis-a-vis name-mangling or the conventions of
symbols.

What, whither, when, how?
Technical Details
Message-ID: <yQOdnQ-qnKiiZ2j3nZ2dnZfqn_udnZ2d@giganews.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 12 Nov 2026 17:41:19 +0000
Newsgroups: comp.lang.c
X-Mozilla-News-Host: snews://giganews.com:443
From: Ross Finlayson <ross.a.finlayson@gmail.com>
Subject: Inversion-of-control and dependency-injection in C
Date: Thu, 12 Nov 2026 09:41:04 -0800
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.6.0
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <yQOdnQ-qnKiiZ2j3nZ2dnZfqn_udnZ2d@giganews.com>
Lines: 46
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-8X4dQgBx5aB/FDKJLozuaPjEJCk7kZRaiBLTFOJe1RLp7I/YBxDExwuEyGz6sO1bbehcn1jyF+Aiynu!Z2CQfkGklhTU0GRaURyX/ZHlpUE2n8z6XcFGTw0oOyELjTRj6hwnpZyxWi02J7IoZbhJKt8K3+k2
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40