plugins/languages/c/skills/core/SKILL.md
C language core conventions covering C11/C17/C23 standard features, coding style, build systems (CMake 3.30+, Meson), and static analysis (clang-tidy, cppcheck, scan-build). Use when writing, reviewing, refactoring, or debugging any C source. Also triggers on "C 标准", "C11", "C17", "C23 特性", "CMake C", "constexpr C", "nullptr C", "_BitInt", "#embed", "[[nodiscard]]", "clang-tidy 配置", "C 编译警告".
npx skillsauth add lazygophers/ccplugin c-coreInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
应作为所有 C 任务(开发 / 测试 / 调试 / 优化)的标准基线。其它 C skill 在本文之上做领域细化。
| 主题 | 跳转 |
|------|------|
| 内存分配 / 泄漏 / 对齐 | c-memory |
| 错误处理 / errno / 安全字符串 | c-error |
| 并发 / 原子 / 线程 | c-concurrency |
| POSIX 系统调用 / 网络 | c-posix |
| 嵌入式 / MISRA / volatile | c-embedded |
-std=c17;使用 C23 特性时通过 __STDC_VERSION__ >= 202311L 条件编译保护。-Wall -Wextra -Werror -pedantic -Wshadow -Wconversion -Wdouble-promotion -Wformat=2。malloc/calloc/realloc 以及系统调用 / 库函数返回值。const;显式 cast 必须有注释解释原因。goto cleanup 统一释放(参考 c-error)。strcpy / sprintf / strcat / gets;使用 snprintf / strncpy + 手动 NUL / memcpy。.c 和 .h 单文件 ≤ 600 行(推荐 200–400)。| 特性 | 关键字 / 语法 | 典型用途 |
|------|-------------|----------|
| 泛型选择 | _Generic | 类型安全宏 |
| 静态断言 | _Static_assert / static_assert | 编译期不变式 |
| 匿名结构 / 联合 | 无名 struct/union 成员 | 简化嵌套访问 |
| 对齐控制 | _Alignas / _Alignof | 缓存行 / SIMD |
| 无返回 | _Noreturn | abort 类函数 |
| 线程局部 | _Thread_local | 线程私有状态 |
| 原子操作 | _Atomic / <stdatomic.h> | 无锁并发(见 c-concurrency) |
-std=c23)| 特性 | 语法 | 编译器(最早稳定) |
|------|------|-------------------|
| nullptr / nullptr_t | if (p == nullptr) | GCC 13 / Clang 16 |
| constexpr 对象与函数 | constexpr int sq(int x){return x*x;} | GCC 14 / Clang 17 |
| typeof / typeof_unqual | typeof(expr) tmp; | GCC 13 / Clang 16 |
| auto 类型推导(语义变更) | auto x = 1;(旧 K&R 风格须写显式类型) | GCC 15 / Clang 18 |
| _BitInt(N) | _BitInt(7) val; | GCC 14 / Clang 16 |
| 二进制字面量 + 数字分隔符 | 0b1010'0011 | GCC 14 / Clang 16 |
| #embed | #embed "data.bin" | GCC 15 / Clang 19 |
| 标准属性 | [[nodiscard]] [[maybe_unused]] [[deprecated]] [[noreturn]] [[fallthrough]] | GCC 14 / Clang 16 |
| VLA {} 零初始化 | int arr[n] = {}; | GCC 14 / Clang 16 |
C2y(下一版)追踪:参见 open-std.org WG14。生产代码不依赖 C2y 草案特性。
// _Generic 类型分发
#define abs_val(x) _Generic((x), \
int: abs, long: labs, float: fabsf, double: fabs)(x)
// 编译期不变式
static_assert(sizeof(int) >= 4, "need >=32-bit int");
static_assert(_Alignof(double) == 8, "double alignment");
// C23 属性带条件保护
#if __STDC_VERSION__ >= 202311L
[[nodiscard]] int compute(int x);
[[maybe_unused]] static void helper(void) { }
#else
int compute(int x);
static void helper(void) { }
#endif
cmake_minimum_required(VERSION 3.30)
project(myproject C)
set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_compile_options(
-Wall -Wextra -Werror -pedantic
-Wshadow -Wconversion -Wdouble-promotion -Wformat=2
)
option(ENABLE_SANITIZERS "Enable ASan+UBSan" OFF)
if(ENABLE_SANITIZERS)
add_compile_options(-fsanitize=address,undefined -fno-omit-frame-pointer -g -O1)
add_link_options(-fsanitize=address,undefined)
endif()
# clang-tidy(项目根放 .clang-tidy 控制规则集)
clang-tidy src/*.c -- -std=c17
# cppcheck
cppcheck --enable=all --inline-suppr --std=c17 --error-exitcode=1 src/
# Clang scan-build(路径敏感)
scan-build -enable-checker security,unix make
.clang-tidy 起步规则集:bugprone-*, cert-*, clang-analyzer-*, misc-*, performance-*, portability-*, readability-*。
-D_FORTIFY_SOURCE=3 -fstack-protector-strong -fstack-clash-protection
-fcf-protection=full -fPIE -pie
-Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack
-std=c17,C23 特性有条件保护-Werror 通过-Wconversion 无警告)strcpy / sprintf / gets / strcat)clang-tidy 与 cppcheck 零警告compile_commands.json 已导出c-status)tools
UI/UX 与布局设计——做界面布局/结构/导航/组件/交互的设计决策。触发:做UI/UX/布局/排版/导航/组件/交互/栅格/响应式/图表选型/字体配对。按媒介路由 HTML/Web、原生 App(iOS/Android/桌面)、CLI、TUI。需后端动态系统不适用;配色/主题/色板走姊妹 skill design-color。
tools
主题与配色设计——做颜色搭配/调色板/主题/品牌色阶/暗模式的设计决策。触发:选配色/调色/主题/色板/品牌色/暗模式/对比度/色盲/UI风格。按媒介路由 HTML/Web(CSS变量)、原生App(平台token)、CLI(ANSI)、TUI(真彩/256/16降级)。保证可访问性(对比度/色盲安全)。需后端动态系统不适用;UI/UX 布局/组件/交互走姊妹 skill design-uiux。
tools
跨任意组件(plugin/skill/agent/command)的验证驱动优化循环纪律 skill。当用户要优化某个已有组件却无明确方向、或要防止改了反而更差(自评乐观偏差 / 多维同改归因失效 / 为凑分加废话膨胀)、或要把一套通用「评分→单变量改→改后验证严格更好才留否则回滚→触顶停」的纪律套到任意组件上时使用。管优化过程本身的纪律(validation gate / ratchet / 独立验证 / 触顶停),不评单组件深度(交 skill-dev),不查插件接线(交 plugin-dev)。仅手动 /optimize-any 触发。
data-ai
两层规则记忆 (基于 .skein/spec)。planning 时 recall 召回相关规则、task finish 后 sediment 沉淀学习 + prune 自动精简过期/重复/断链规则。core 常驻硬规 + recall 按需召回, 经判定门自动写盘 (不逐次问用户)。产出 .skein/spec 下 core/recall 规则文件 + index。另支持空仓 bootstrap 播种规则基线、记忆大面积失效 (大重构/换栈) 时 reconstruct 可逆归档后按项目类型分型重建、maintain 手动体检 (超预算/stale/断链/重复/废弃, --apply 自动修复)、auto-fix (Stop hook 写 .pending-fix 标记 → main 派 skein-specer bg 跑 maintain --apply 全自动修, 断链只报告)。