Article View: comp.lang.c
Article #1495Re: Inversion-of-control and dependency-injection in C
From: Ross Finlayson
Date: Thu, 12 Nov 2026 21:15
Date: Thu, 12 Nov 2026 21:15
41 lines
3467 bytes
3467 bytes
On 11/12/2026 12:11 PM, Lew Pitcher wrote: > On Thu, 12 Nov 2026 09:41:04 -0800, Ross Finlayson wrote: > >> 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. > > Pardon my impertinence, but this sounds like a homework problem to me. > > Could you rephrase your question without the academic wording? > Not at all, meaning, no offense taken. How about "writing testable code", what are common frameworks or best practices for "writing testable code" in C. I'd suggest abstraction and layers and modularity and composability, and having an inversion-of-control/dependency-injection approach, a convention moreso than a framework, which pretty much means wrapping all the standard functions, then about for example having an include where those are wrapper functions to stub and mock, and another include where those are macros, or, perhaps, using includes, to point the include directory for the standard library, into instead what makes for stubbable/mockable calls to standard library and system functions, or just leaving the headers alone and linking to modules that aren't the standard libraries, this being an example of something like "can't mock strftime", or, for an example. Then, about the modularity, and pointers (to pointers to pointers to pointers, ...) to functions, then seems about conventions of types for typeof and the like about that like anybody else I rely on the compiler to fail with -Wall and failing on warnings to catch type errors, ..., has that I want to program to interfaces and then have objects composable, ..., about using conditions of the build, to, basically make for test-time targets and run-time targets, with actually testing the code that goes into the build.
Technical Details
Message-ID:
<16ScnZKb_MQfsWv3nZ2dnZfqn_idnZ2d@giganews.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-4.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mailReferences:
<yQOdnQ-qnKiiZ2j3nZ2dnZfqn_udnZ2d@giganews.com> <11d56gl$3ud5q$1@dont-email.me>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-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-4.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 12 Nov 2026 21:15:46 +0000 Subject: Re: Inversion-of-control and dependency-injection in C Newsgroups: comp.lang.c References: <yQOdnQ-qnKiiZ2j3nZ2dnZfqn_udnZ2d@giganews.com> <11d56gl$3ud5q$1@dont-email.me> From: Ross Finlayson <ross.a.finlayson@gmail.com> Date: Thu, 12 Nov 2026 13:15:25 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <11d56gl$3ud5q$1@dont-email.me> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <16ScnZKb_MQfsWv3nZ2dnZfqn_idnZ2d@giganews.com> Lines: 41 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-vNw1YpVUtJoSsAaaA5Cutec6tC8c88LJPYE5Aj5dvcM37/C1MJBs4BCyJWsLqZDsLtV2nXUut5XA1jf!BJuJJsqCmSrF+q23eQx6/VsXboH79K9Vk+pUoIALucC5Bw3/pVX/Dh/3Q2J0qMwPhzLfYz1lMS42 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