Skip to content
Back to skills

Writing C99

ASecurity

Use when writing, editing, or reviewing plain C99 code such as libraries, CLI tools, and system utilities. Triggers on `.c`/`.h` files, designated initializers, fixed-width types, const-correctness, malloc/free, inline functions vs macros, string handling, error return codes, sanitizers, even when the user doesn't say 'C'.

  • 6 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 30, 2026
ai-agentsgoapi

Works with

  • cli
  • api
  • mcp

Security analysis

A100/100

Pro scans all 15 files and shows the line behind each finding

Scanned November 30, 2026

npx -y skills add xonovex/platform --skill writing-c99 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Writing C99?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Writing C99
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/xonovex-writing-c99/badge)](https://www.skillsdirectory.com/skills/xonovex-writing-c99)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: writing-c99
description: "Use when writing, editing, or reviewing plain C99 code such as libraries, CLI tools, and system utilities. Triggers on `.c`/`.h` files, designated initializers, fixed-width types, const-correctness, malloc/free, inline functions vs macros, string handling, error return codes, sanitizers, even when the user doesn't say 'C'."
---

# C99 Coding Guidelines

Write portable C99 with explicit ownership, bounded operations, and checked errors.

## Essentials

- **Memory management** - Free all heap allocations, avoid leaks, see [references/memory-management.md](references/memory-management.md)
- **Modern C99** - Use `const`, designated initializers (ZII), small functions, see [references/designated-initializers.md](references/designated-initializers.md), [references/const-correctness.md](references/const-correctness.md)
- **Fixed-width types** - Name widths with `<stdint.h>` for sized/serialized data; `size_t` for counts and indices, see [references/fixed-width-types.md](references/fixed-width-types.md)
- **Type safety** - Favor `inline` functions over macros where practical, see [references/inline-functions.md](references/inline-functions.md)
- **Quality** - Pin strict C99, treat warnings as errors, keep an ASan/UBSan debug build, run static analysis, see [references/build-and-warnings.md](references/build-and-warnings.md)

## Best practices

- **Error handling** - Use return codes, check all fallible operations, see [references/error-handling.md](references/error-handling.md)
- **Value-oriented APIs** - Return small results by value; reserve out-params for large or multiple results, see [references/value-types.md](references/value-types.md)
- **Strings** - Borrow length-carrying views, write through bounded builders over caller memory, not `strlen`/`strcat`/`strtok` rescans, see [references/string-views.md](references/string-views.md)
- **Input validation** - Check bounds, NULL pointers, division by zero
- **Readability** - Small functions, clear naming, comments for non-obvious logic
- **Paradigm** - Functional style (pure functions, explicit context) → **applying-fp**; object/data modeling → **applying-oop**

## Gotchas

- Signed integer overflow is undefined behavior, even `INT_MAX + 1` lets the compiler eliminate "impossible" code paths
- Strict aliasing means casting `int*` to `float*` is UB unless via `union` or `memcpy`: silently miscompiled at higher optimization levels
- `malloc` returns memory that's max-aligned; custom arenas must preserve alignment for `_Bool`/`double`/SIMD types
- Designated initializers (`.field = x`) zero-fill unmentioned members: a missing field becomes silent zero, not a compile error
- `long` is 32-bit on Windows and 64-bit on most 64-bit Unix targets: a struct of `int`/`long` serializes and hashes differently per platform; use `<stdint.h>` exact-width types for any stored or shared data
- Comparing a signed `int` against an unsigned `size_t` converts the `int`: a negative value becomes a huge `size_t` and the bounds check passes; keep counts/indices in `size_t` end to end
- Return-by-value is for _small_ PODs; returning a large struct just copies it: large or caller-owned results still take a pointer
- `-std=c99` usually still means the GNU dialect: set `C_EXTENSIONS OFF` for true ISO C99, then `#define _XOPEN_SOURCE 700` or POSIX calls (`readlink`, `strnlen`, `ssize_t`) become implicit-declaration errors
- `-Wextra`'s `-Wmissing-field-initializers`/`-Wmissing-braces` fire on intentional zero-init: suppress those two, keep the rest of `-Werror`

## Progressive disclosure

- Read [references/build-and-warnings.md](references/build-and-warnings.md) - Load when configuring the C standard, feature-test macros, warning flags, or sanitizers
- Read [references/fixed-width-types.md](references/fixed-width-types.md) - Load when choosing integer types for struct fields, serialized data, counts, or indices
- Read [references/string-views.md](references/string-views.md) - Load when handling strings without repeated terminator scans or hidden allocations
- Read [references/value-types.md](references/value-types.md) - Load when designing function signatures: returning results by value vs. out-parameters
- Read [references/memory-management.md](references/memory-management.md) - Load when allocating memory or managing resource lifetimes
- Read [references/designated-initializers.md](references/designated-initializers.md) - Load when initializing structs or arrays with specific values
- Read [references/inline-functions.md](references/inline-functions.md) - Load when replacing macros or writing small utility functions
- Read [references/compound-literals.md](references/compound-literals.md) - Load when creating temporary values without named variables
- Read [references/const-correctness.md](references/const-correctness.md) - Load when marking immutable data or understanding pointer const
- Read [references/error-handling.md](references/error-handling.md) - Load when implementing error codes or handling failures

Files in this skill

  • SKILL.md4.9 KB
  • eval-output.json3.1 KB
  • eval-trigger.json5.6 KB
  • moon.yml86 B
  • references/build-and-warnings.md4.5 KB
  • references/compound-literals.md388 B
  • references/const-correctness.md385 B
  • references/designated-initializers.md1.1 KB
  • references/error-handling.md1.3 KB
  • references/fixed-width-types.md2.6 KB
  • references/inline-functions.md583 B
  • references/memory-management.md544 B
  • references/string-views.md2 KB
  • references/value-types.md1.9 KB
  • sources.json3.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.