Skip to content

chore: C99/C11 modernization for readability #74

@Liam-Deacon

Description

@Liam-Deacon

Problem

Large parts of the codebase are written in a C89/C90 style (e.g., loop-scope variables declared at function scope, manual index manipulation, macro-heavy helpers). This makes the code harder to read and reason about, and it limits the use of clearer C99/C11 constructs.

Proposed direction

Adopt C99 as the project baseline (and selectively use C11 where it improves clarity) to modernize code style and reduce macro reliance.

Examples (non-exhaustive)

  • Loop-scope variables: prefer for (size_t i = 0; i < n; i++) over function-scope size_t i; + loop reuse. This removes accidental reuse and keeps variable lifetimes tight.
  • Safer/clearer helpers: replace macro-heavy constructs (e.g., MIN/MAX, assertion macros with side effects) with static inline functions. This improves type safety and debuggability.
  • stdbool/size_t: use <stdbool.h> for bool and <stddef.h>/size_t for sizes instead of ad‑hoc int/unsigned long usage to reduce format/overflow mistakes.
  • Designated initializers: prefer { .field = value } for clarity in large structs.
  • Explicit casts and enums: tighten enum usage and avoid implicit int assumptions.

Benefits

  • Better readability and maintainability (fewer hidden macro tricks).
  • Safer, more explicit code with tighter variable scopes.
  • Easier static analysis and fewer false positives from linters.
  • Simplified onboarding and contribution (modern C expectations).

Acceptance criteria

  • Documented C99/C11 baseline (CMake + Autotools) and scope of modernization.
  • Initial pass converts a small, representative subset of files with clear before/after examples.
  • No functional regressions (build + existing tests pass).

Notes

  • Keep changes incremental (file-by-file) to avoid huge PRs.
  • Be conservative with C11 features; only use them where they clearly improve readability or safety.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions