{
  "id": 4757391,
  "title": "Program Organization (with Examples in C)",
  "url": "https://urgent.news/2026/09/01/program-organization-with-examples-in-c",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-01T00:54:38.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/pauljlucas/program-organization-with-examples-in-c-20o1"
  },
  "original_language": "en",
  "account": "Program Organization in Tidy, a Mid-Sized C Program\n\nIntroduction\nIn my book Why Learn C, Chapter 13, Program Organization, I discussed how most C programs consist of multiple source (.c) and header (.h) files. Typically, each .c file implements a specific functionality, while the corresponding .h file provides a public API for using that functionality. These pairs of files often work together to form a module or specialized aspect of the program. For example, a color.c file contains functions for printing text in color to a terminal, while color.h contains their declarations.\n\nProgram Structure in Tidy\nTidy, a mid-sized C program, demonstrates how to organize source files in a more complex project. Compared to the smaller ad program, Tidy is approximately three times larger. Here are some of its source files:\n\n- array.c\n- file_ext.c\n- path_util.c\n- symbol.h\n- array.h\n- file_ext.h\n- path_util.h\n- toml_lite.c\n- bit_util.c\n- fnv1a.c\n- path_util_test.c\n- toml_lite.h\n- bit_util.h\n- fnv1a.h\n- pjl_config.h\n- toml_test.c\n- clang_util.c\n- hash_table.c\n- print.c\n- trans_unit.c\n- cli_options.c\n- proxies.c\n- type_traits.h\n- cli_options.h\n- include-tidy.c\n- proxies.h\n- typedef.c\n- color.h\n- include-tidy.h\n- red_black.c\n- typedef.h\n- color.h\n- include.c\n- red_black.h\n- unit_test.c\n- config.h\n- include.h\n- red_black_test.c\n- unit_test.h\n- config_file.c\n- ipath.c\n- strbuf.c\n- util.c\n- config_file.h\n- ipath.h\n- strbuf.h\n- util.h\n- cxx.c\n- options.c\n- strbuf_test.c\n- cxx.h\n- symbol.c\n\nComponents of Tidy\nTidy can be broken down into several types of components:\n\n1. Program-specific data structures and algorithms: Tidy includes a data structure to represent symbols referenced in a program, defined in symbol.h with implementations in symbol.c. This C++-specific code was later moved to cxx.c for better organization.\n\n2. Generic data structures and algorithms: Tidy utilizes dynamic arrays, hash tables, red-black trees, and string buffers, which are necessary in C programs as they don't exist in the C standard library.\n\n3. Program options: These allow the behavior of Tidy to be customized, such as comment styles, alignment columns, and colored output.\n\n4. Command-line parsing: Tidy uses command-line options to set program options, often in a 1:1 correspondence with the program options.\n\n5. Configuration file parsing: Tidy can also parse configuration files to set program options, which can be cumbersome to set from the command line.\n\n6. Program-specific utilities: Functions that aren't entirely generic but are used in multiple places or improve the use of third-party libraries, like functions for dealing with Libclang in Tidy.\n\n7. Generic utilities: Macros, error-handling functions, string-handling functions, and others that are useful across various parts of the program.\n\n8. Test code: Tidy includes a small unit-test framework, test executables, and a functional-test framework.\n\nConclusion\nOrganizing source files effectively is crucial for maintaining and understanding larger programs. By separating program-specific and generic components, maximizing the reuse of generic components, and keeping program-specific code manageable, developers can create cleaner, more maintainable codebases. Tidy serves as an example of how to apply these principles in a mid-sized C program.",
  "summary": "Introduction In my book Why Learn C , Chapter 13, Program Organization , I wrote in part: For all but the most trivial programs, a typical C program is composed of several source ( .c ) files and header ( .h ) files. Often, .c and .h files come in pairs where the .c implements some functionality and the .h provides the “public” API for using it. All the functions comprising a program are spread…",
  "key_points": [
    "Tidy is a mid-sized C program, approximately three times larger than ad",
    "Tidy demonstrates effective organization of source files to maintain and understand larger programs"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}