Complete AI TrainingYourJobSkills for your job

Skills / super-code

c

Language-specific super-code guidelines for c.

new

C: Idiomatic Efficiency Reference

When to Use

  • Use this skill when the task matches this description: Language-specific super-code guidelines for c.

Table of Contents

  1. [Memory Management](#memory)
  2. [Pointers & Arrays](#pointers)
  3. [Error Handling](#errors)
  4. [Strings](#strings)
  5. [Structs & Enums](#structs)
  6. [Preprocessor & Headers](#preprocessor)
  7. [Anti-patterns specific to C](#antipatterns)

1. Memory Management {#memory}

// ❌ malloc without checking return value
char *buf = malloc(size);
strcpy(buf, src);

// ✅
char *buf = malloc(size);
if (!buf) return -ENOMEM;
memcpy(buf, src, size);
// ❌ Casting malloc result (unnecessary in C, hides missing #include)
int *p = (int *)malloc(n * sizeof(int));

// ✅
int *p = malloc(n * sizeof *p);
// ❌ free without nulling (dangling pointer risk in long-lived scope)
free(ptr);
// ... later code might use ptr

// ✅
free(ptr);
ptr = NULL;
// ❌ Forgetting to free on early-return paths
char *a = malloc(100);
char *b = malloc(200);
if (!b) return -1; // leaks a

// ✅ — single cleanup label
char *a = NULL, *b = NULL;
a = malloc(100);
if (!a) goto cleanup;
b = malloc(200);
if (!b) goto cleanup;
// ... use a, b ...
cleanup:
    free(b);
    free(a);

**Use sizeof ptr instead of sizeof(Type) — it stays correct when the type changes.*


2. Pointers & Arrays {#pointers}

Subscribers only

The full skill, its 1 bundled files and every download is included with every paid Complete AI plan.

Details

Sourcecommunity
License
Risk labelsafe ("critical" means the skill may run commands or touch files — read before use)
FilesSKILL.md
Added2026-06-16

Related skills

bash

Language-specific super-code guidelines for bash.

cpp

Language-specific super-code guidelines for cpp.

csharp

Language-specific super-code guidelines for csharp.

dart

Language-specific super-code guidelines for dart.

elixir

Language-specific super-code guidelines for elixir.

go

Language-specific super-code guidelines for go.