My advice on implementing stuff in C:
My advice on implementing stuff in C:
Posted Oct 18, 2010 19:17 UTC (Mon) by cmccabe (guest, #60281)In reply to: My advice on implementing stuff in C: by marcH
Parent article: Russell: On C Library Implementation
> systems allow nesting, "static" in C gives you only one level. And this
> puts severe constraints on how you split your project into files.
It's easy enough to split your project into multiple libraries. Then each library can do its own self-contained thing. Hopefully the graph of dependencies is a tree. I have programmed C in this style before. Build systems like CMake make it easy.
> While I share the hate for these code generators, a macro system does not
> seem like the solution to me. Examples?
Macros can be used for:
* Initializing structs in a very repetitive way.
* Generating short functions that do something trivial, like accessors. High level languages like ruby have :attr_accessor, but that relies on metaprogramming which isn't available in a low-level language like C.
* Generic programming
