patternscontext-struct
Context Struct Pattern (C-Specific) pattern for C development
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Context Struct Pattern (C-Specific)
Pass state explicitly as struct pointer parameter rather than using globals. First parameter to functions is context containing state and dependencies.
ikigai Application
Core pattern: Every module uses this:
-
ik_repl_ctx_t- REPL state -
ik_term_ctx_t- Terminal state -
ik_scrollback_t- Scrollback state -
ik_env_t- Runtime environment (planned)
Convention: Context is first parameter after talloc context:
res_t ik_scrollback_append(ik_scrollback_t *ctx, const char *line);
Benefits:
- No global state
- Multiple instances possible
- Explicit dependencies
- Testable (inject mock contexts)
See: project/explicit_context.md for ik_env_t design.
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-01-20
- Index updated
- 2026-01-26
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!