Communitygithub.com

JantonioFC/skillsbank

Sprachspezifische Super-Code-Richtlinien für C.

Was ist skillsbank?

Dieses Skill bietet eine umfassende und idiomatische Referenz für die C-Programmierung, die sich auf Effizienz und korrekte Sprachverwendung konzentriert. Es deckt wesentliche Bereiche wie Speicherverwaltung, Zeiger und Arrays, Fehlerbehandlung, Zeichenketten, Strukturen und Aufzählungen sowie Präprozessor-Direktiven ab. Der Skill ist besonders nützlich für Entwickler, die qualitativ hochwertigen, wartbaren C-Code schreiben möchten, indem er gängige Anti-Patterns aufzeigt und bewährte Idiome bereitstellt. Die Referenz wird als SKILL.md-Dokument bereitgestellt und ist plattformunabhängig, sodass sie in jeder C-Entwicklungsumgebung (z.B. mit Claude Code, Cursor oder Codex) angewendet werden kann. Jeder Abschnitt enthält Codebeispiele mit ❌- und ✅-Markierungen, die schlechte und gute Praktiken gegenüberstellen, sowie klare Erklärungen, warum die empfohlenen Ansätze vorteilhaft sind. Der Skill betont die Bedeutung von typsicherem Code, effizienter Ressourcenverwaltung und konsistenten Fehlerbehandlungsmustern.

Funktioniert mit~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/JantonioFC/skillsbank/tree/HEAD/skills/c

In Ihrer bevorzugten KI fragen

Öffnet einen neuen Chat, in dem dieser Agent-Skill bereits geladen ist.

Dokumentation

C: Idiomatische Effizienz-Referenz

Inhaltsverzeichnis

  1. Speicherverwaltung
  2. Zeiger & Arrays
  3. Fehlerbehandlung
  4. Zeichenketten
  5. Strukturen & Aufzählungen
  6. Präprozessor & Header
  7. Anti-Patterns spezifisch für C

1. Speicherverwaltung {#speicher}

// ❌ malloc ohne Überprüfung des Rückgabewerts
char *buf = malloc(size);
strcpy(buf, src);

// ✅
char *buf = malloc(size);
if (!buf) return -ENOMEM;
memcpy(buf, src, size);
// ❌ Cast des malloc-Ergebnisses (in C unnötig, versteckt fehlendes #include)
int *p = (int *)malloc(n * sizeof(int));

// ✅
int *p = malloc(n * sizeof *p);
// ❌ free ohne Nullsetzen (Risiko von baumelnden Zeigern in langlebigen Bereichen)
free(ptr);
// ... späterer Code könnte ptr verwenden

// ✅
free(ptr);
ptr = NULL;
// ❌ Vergessenes Freigeben bei frühen Rückkehrpfaden
char *a = malloc(100);
char *b = malloc(200);
if (!b) return -1; // gibt a nicht frei

// ✅ — ein einzelnes Bereinigungslabel
char *a = NULL, *b = NULL;
a = malloc(100);
if (!a) goto cleanup;
b = malloc(200);
if (!b) goto cleanup;
// ... a, b verwenden ...
cleanup:
    free(b);
    free(a);

Verwenden Sie sizeof *ptr anstelle von sizeof(Typ) — es bleibt korrekt, wenn sich der Typ ändert.


2. Zeiger & Arrays {#zeiger}

// ❌ Manuelle Array-Größenverfolgung
void process(int *arr, int len) { ... }
process(data, 10);

// ✅ — Größe zusammen mit Zeiger übergeben oder ein Struct verwenden
typedef struct { int *data; size_t len; } IntSlice;
// ❌ Zeigerarithmetik, wo Array-Indizierung klarer ist
*(arr + i) = value;

// ✅
arr[i] = value;
// ❌ VLA im Produktionscode (Stapelüberlauf-Risiko, optional in C11+)
int arr[n];

// ✅
int *arr = malloc(n * sizeof *arr);
if (!arr) return -ENOMEM;
// ... arr verwenden ...
free(arr);

3. Fehlerbehandlung {#fehler}

// ❌ Verwenden magischer Zahlen für Fehlerrückgaben
if (do_thing() == -1) { ... }

// ✅ — benannte Fehlercodes definieren oder verwenden
#include <errno.h>
if (do_thing() < 0) {
    perror("do_thing");
    return errno;
}
// ❌ Tief verschachtelte Fehlerprüfungen
int r1 = step1();
if (r1 == 0) {
    int r2 = step2();
    if (r2 == 0) {
        int r3 = step3();
        // ...
    }
}

// ✅ — frühe Rückkehr / goto cleanup
if (step1() < 0) goto fail;
if (step2() < 0) goto fail;
if (step3() < 0) goto fail;
return 0;
fail:
    cleanup();
    return -1;

goto cleanup ist idiomatisches C für Ressourcenbereinigung — vermeiden Sie es nicht grundsätzlich.


4. Zeichenketten {#zeichenketten}

// ❌ strcpy ohne Bereichsprüfung
strcpy(dest, src);

// ✅
strncpy(dest, src, sizeof(dest) - 1);
dest[sizeof(dest) - 1] = '\0';
// oder besser: snprintf(dest, sizeof(dest), "%s", src);
// ❌ strcmp-Mißbrauch
if (str == "hello") { ... } // vergleicht Zeiger, nicht Inhalt

// ✅
if (strcmp(str, "hello") == 0) { ... }
// ❌ Zeichenketten mit wiederholtem strcat erstellen (O(n²))
char result[1024] = "";
for (int i = 0; i < n; i++) {
    strcat(result, items[i]);
}

// ✅ — Schreibposition verfolgen
char result[1024];
int pos = 0;
for (int i = 0; i < n && pos < (int)sizeof(result); i++) {
    pos += snprintf(result + pos, sizeof(result) - pos, "%s", items[i]);
}

Bevorzugen Sie snprintf gegenüber sprintf — immer.


5. Strukturen & Aufzählungen {#strukturen}

// ❌ Bloßes Struct, das überall das `struct`-Schlüsselwort erfordert
struct point { int x, y; };
struct point p = {1, 2};

// ✅
typedef struct { int x, y; } Point;
Point p = {1, 2};
// ❌ Uninitialisiertes Struct
Point p;
use(p.x); // UB

// ✅
Point p = {0};
// ❌ Magische Integer-Konstanten
if (state == 3) { ... }

// ✅
typedef enum { STATE_IDLE, STATE_RUNNING, STATE_DONE } State;
if (state == STATE_DONE) { ... }

6. Präprozessor & Header {#praeprozessor}

// ❌ Makro, wo eine Inline-Funktion funktioniert (keine Typsicherheit, doppelte Auswertung)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
MAX(x++, y) // x wird zweimal inkrementiert, wenn x > y

// ✅
static inline int max_int(int a, int b) { return a > b ? a : b; }
// ❌ Keine Include-Guard
// my_header.h
struct Foo { int x; };

// ✅
#ifndef MY_HEADER_H
#define MY_HEADER_H
struct Foo { int x; };
#endif
// oder: #pragma once (weit verbreitet, nicht standardisiert)

Halten Sie Makros für bedingte Kompilierung und Konstanten. Verwenden Sie static inline für Logik.


7. Anti-Patterns spezifisch für C {#antipatterns}

Anti-PatternBevorzugt
sprintfsnprintf mit Puffergröße
getsfgets (gets wurde in C11 entfernt)
Cast des malloc-Ergebnissesimplizite void*-Konvertierung nutzen
sizeof(Typ) in mallocsizeof *ptr
VLA für große/laufzeitbestimmte ArraysHeap-Allokation
void*-Callbacks ohne Kontextparametervoid *ctx zusammen mit Funktionszeiger übergeben
Globaler veränderlicher ZustandZustand über Struct-Zeiger übergeben
assert für Laufzeitfehlerbehandlungkorrekte Fehlerrückgabecodes
Fehlendes const bei schreibgeschützten Zeigerparameternconst char *str
Mischen von vorzeichenbehafteten/vorzeichenlosen Vergleichenkonsistente Typen verwenden, explizit casten

Einschränkungen

  • Dies sind sprachspezifische Richtlinien und decken keine übergreifenden Architekturentscheidungen ab.
  • Übermäßige Verdichtung könnte die Lesbarkeit verringern; wenden Sie Ihr Urteilsvermögen an.

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

JantonioFC/skillsbank

AI-powered image editing with style transfer and object removal

JantonioFC/skillsbank

Internationalization and localization patterns. Detecting hardcoded strings, managing translations, locale files, RTL support.

JantonioFC/skillsbank

Analise e auditoria de editais de leilao judicial e extrajudicial. Riscos ocultos, clausulas perigosas, debitos, ocupante e classificacao da oportunidade.

JantonioFC/skillsbank

Embed Photopea in web apps using photopea.js. Covers embedding, file I/O, scripting, exporting, layers, text, filters, and the full Photoshop-compatible API.

JantonioFC/skillsbank

Best practices for Remotion - Video creation in React

JantonioFC/skillsbank

Generate walkthrough videos from Stitch projects using Remotion with smooth transitions, zooming, and text overlays

JantonioFC/skillsbank

Seek and analyze video content using Memories.ai Large Visual Memory Model for persistent video intelligence

JantonioFC/skillsbank

Writes complete, structured landing pages optimized for SEO ranking, AEO citation, and visitor conversion. Activate when the user wants to write or generate a landing page for a product, service, or offer.

JantonioFC/skillsbank

Video and audio perception, indexing, and editing. Ingest files/URLs/live streams, build visual/spoken indexes, search with timestamps, edit timelines, add overlays/subtitles, generate media, and create real-time alerts.

JantonioFC/skillsbank

Upload, stream, search, edit, transcribe, and generate AI video and audio using the VideoDB SDK.

JantonioFC/skillsbank

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

JantonioFC/skillsbank

Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios, and portfolios that convert visitors into opportunities.

JantonioFC/skillsbank

Tool lifecycle UI components for React/Next.js from ui.inference.sh. Display tool calls: pending, progress, approval required, results. Capabilities: tool status, progress indicators, approval flows, results display. Use for: showing agent tool calls, human-in-the-loop approvals, tool output. Triggers: tool ui, tool calls, tool status, tool approval, tool results, agent tools, mcp tools ui, function calling ui, tool lifecycle, tool pending

JantonioFC/skillsbank

Security audit, hardening, threat modeling (STRIDE/PASTA), Red/Blue Team, OWASP checks, code review, incident response, and infrastructure security for any project.

JantonioFC/skillsbank

When the user wants help with paid advertising campaigns on Google Ads, Meta (Facebook/Instagram), LinkedIn, Twitter/X, or other ad platforms. Also use when the user mentions 'PPC,' 'paid media,' 'ROAS,' 'CPA,' 'ad campaign,' 'retargeting,' 'audience targeting,' 'Google Ads,' 'Facebook ads,'...

JantonioFC/skillsbank

Create AI avatar and talking head videos with OmniHuman, Fabric, PixVerse via inference.sh CLI. Models: OmniHuman 1.5, OmniHuman 1.0, Fabric 1.0, PixVerse Lipsync. Capabilities: audio-driven avatars, lipsync videos, talking head generation, virtual presenters. Use for: AI presenters, expla...

JantonioFC/skillsbank

Create AI marketing videos for ads, promos, product launches, and brand content. Models: Veo, Seedance, Wan, FLUX for visuals, Kokoro for voiceover. Types: product demos, testimonials, explainers, social ads, brand videos. Use for: Facebook ads, YouTube ads, product launches, brand awarene...

JantonioFC/skillsbank

Generate AI videos with Google Veo, Seedance, Wan, Grok and 40+ models via inference.sh CLI. Models: Veo 3.1, Veo 3, Seedance 1.5 Pro, Wan 2.5, Grok Imagine Video, OmniHuman, Fabric, HunyuanVideo. Capabilities: text-to-video, image-to-video, lipsync, avatar animation, video upscaling, fole...

JantonioFC/skillsbank

Production-ready CI/CD configurations for Playwright — GitHub Actions, GitLab CI, CircleCI, Azure DevOps, Jenkins, Docker, parallel sharding, reporting, code coverage, and global setup/teardown.

JantonioFC/skillsbank

You are an expert copy editor specializing in marketing and conversion copy. Your goal is to systematically improve existing copy through focused editing passes while preserving the core message.

Verwandte Skills