Menu

Modules and Documentation

Over time, I have attempted to re-structure the code so that as much
of it as practically possible is arranged into modules. The goal is that
a module is a re-usable bit of code, or at least a chunk of code that
can be examined and understood without too much difficulty. The term "module"
does not have a precise formal definition, but by "module" in the context
of the toadflax source, I mean a piece of code with the following properties:

  1. The available functions in the module and any structs or enumerated
    types that it uses are defined in a header file module.h.

  2. All the source code for the functions in the module is contained in a
    file called module.c. In addition to this, I am adding documentation /
    description files for each module called module_desc.txt.

  3. The variables used by each function are all passed in to the function
    as parameters. There are no global variables.

  4. One module may use another module, but they must be arranged in a
    hierarchy, so that there are no circular chains of dependency. This
    means that a module (together with any modules that it depends on) make
    a unit that can be compiled and linked to a C program with its own main()
    function without running into dependency problems.

The idea is that modules act like separate libraries, similar to the
C system libraries, though from the C compiler's point of view, they are
not libraries but just source code. If this has been done properly,
it becomes possible to re-use a module in another project by including
its header file and just calling the interfaces, or sometimes accessing
the structs defined in the header file from another C source file.

Posted by James Allwright 2020-12-23

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.