Article View: comp.lang.c
Article #1627Re: Inversion-of-control and dependency-injection in C
From: Ross Finlayson
Date: Wed, 18 Nov 2026 12:13
Date: Wed, 18 Nov 2026 12:13
107 lines
6988 bytes
6988 bytes
On 11/13/2026 08:54 AM, David Brown wrote: > His posts are not written by AI - no AI writes that badly. And it is > not so void of meaning and grammar that it is randomly generated. Ross > has written posts in this style for many years in several Usenet groups. > I find it hard to believe that someone would spend so much time and > effort for a joke. > Then, in another thread, bringing it back here: >> Here then for example, what I'm trying to figure out is basically >> how to make for C what's in C++ without being in C++ that's yet >> readily adaptable for calling and being called from and into C++ >> from C. Like, for example, "sequence" or "iter", and "lister" >> and the like, then for something like "C11 _Generic", making accounts >> of generics the types in C vis-a-vis the polymorphic class model >> in C++, about "sized" or accounts like "characteristics" of access >> of arrays, pointer-offsets, lists, otherwise the usual things, >> "holders", "getters and setters", then about "libraries" and >> "components", after things like "success_t, error_t, and return_t, >> for context_t", definitions of the patterns, that would be generally >> suitable for writing libraries in C and having them callable and >> calling to and from C++, these are the kinds of things I'm liking >> to figure out. >> >> >> Like for example about how to pass an allocator into C, or making >> access of ctx_new/ctx_del or ctx_init/ctx_fini, those being about >> storage or lifetime and ownership and responsibility, then for >> things like "emit_log" and "emit_metric" and "emit_dump", these >> are the kinds of things that later always live in any sort of >> application framework, for making good-style. >> > > Why not just write : > > """ > How do I write C++ code in C? > """ > > The answer then would be, you don't. Write C++ code in C++. Write C > code in C. > Here the points under consideration are that C++ has some relevant constructs that to use the same patterns in C, then to make for the _interoperability_, has for example that libraries of most any usual sort result their symbols, those being of C, or as after name-mangling (a convention of expressing the namespaces and constructs encoding the names/symbols as C defines for what C++ models, name-mangling, where "the mangle" is a steam-press for the ironing of sheets, where the common meaning is "fold, spindle, and mutilate"), there's that "writing C++ in C", is to make it adapt-able. Then, other accounts involve the system, for example malloc/free, vis-a-vis, allocators, and that C++'s account of new/delete, has also an account of pretty much every constructor allowing the passing of an allocator, for example about free-lists/arenas/slabs, about how to make a _pattern_ so that either the library interface signature has function-pointers for acquire-release, or, for example, there's a convention where each process/thread has a global-variable (called thread-local in a thread, global to the thread) with function pointers for acquire/release. It's similar with stdio, or for example loggers, usually considered "static" (or extern) to the process to result a global entry-point for the rest of the routine, or, what makes for that it gets passed to every library-function or installed in the context passsed to every library function, about what aren't "classes" and "instances" like in C++ which is defined in the language, _yet so model those_, why it's a thing. Other examples of accounts for example make for list-adapters or iterators or accounts of sequences then about treating arrays and lists as the same (while they have different characteristics of access, the "access-patternry"), then for example about associative arrays and sets and the like then into traversals for trees and graphs and the like, where for example many "loosely-typed" languages of the day (like JavaScript, Python, ...) have that's _default_ with the "slots" the associative-array, vis-a-vis something like "the shell language" and accounts of attributes, and behaviors for arrays and associative-arrays, those being considered general. So, the idea is that something like C11 has something like "_Generic" keyword to employ, that instead of writing to a concrete implementation of an array or list, instead to write to the _adapters_ of these, in C, which can be more direct for C++, with C++'s great account of, "Abstraction", for the abstract and the concrete, and that anything's both abstract and concrete. C and C++ are different accounts: they're also together an account. Then, the resulting artifacts: has that C++ can link as it were to the C symbols, and even the C can link as it were to name-mangled C++, not that anybody ever does that since it involves the model in the run-time their interpretation, point being libraries to be interoperable with both C and C++ have C exports, then that it's to be expected that C++ for example can deal with the allocator or I/O stream, wrapping it into the C++ from a C way that must be contrived. Then, here C and C++ are always considered "C/C++", since, the implementations have largely agreed about the object-files and the libraries, that it's so.
Technical Details
Message-ID:
<PKGcne0xA53EC2D3nZ2dnZfqn_udnZ2d@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-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mailReferences:
<yQOdnQ-qnKiiZ2j3nZ2dnZfqn_udnZ2d@giganews.com> <11d56gl$3ud5q$1@dont-email.me> <11d6vjp$qhu8$1@raubtier-asyl.eternal-september.org> <dsednTD-Fblclmr3nZ2dnZfqnPWdnZ2d@giganews.com> <11d738r$ru7a$1@dont-email.me> <11d75i7$spj0$1@dont-email.me> <11d7c8k$173nk$1@dont-email.me> <11d7fbv$1839o$2@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-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 18 Nov 2026 12:13:12 +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> <11d6vjp$qhu8$1@raubtier-asyl.eternal-september.org> <dsednTD-Fblclmr3nZ2dnZfqnPWdnZ2d@giganews.com> <11d738r$ru7a$1@dont-email.me> <11d75i7$spj0$1@dont-email.me> <11d7c8k$173nk$1@dont-email.me> <11d7fbv$1839o$2@dont-email.me> From: Ross Finlayson <ross.a.finlayson@gmail.com> Date: Wed, 18 Nov 2026 04:13:07 -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: <11d7fbv$1839o$2@dont-email.me> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <PKGcne0xA53EC2D3nZ2dnZfqn_udnZ2d@giganews.com> Lines: 107 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-8NkVyAePWUfJQVjQfsB3BJeH0voSJ0E9j+LQhlx7UEvMXIOwuoyJBULqAIknF7mkB6C9M1OBwhlnTTP!Sm0oYC5tVavezh0+4WOzt7KGjm4W4oLJKYFoN1++ZjfhwbNyHww3Xmjtf73d2BGW7X8nvWg1vydx 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