Stats
Actions
Tags
Help us improve
Share bugs, ideas, or general feedback.
From c
C语言核心规范,涵盖C11/C17/C23标准特性、编码约定、构建系统(CMake/Makefile)和静态分析(clang-tidy/cppcheck)。适用于编写、审查、调试任何C代码。
npx claudepluginhub lazygophers/ccplugin --plugin cHow this skill is triggered — by the user, by Claude, or both
Slash command
/c:coresonnetThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- **dev** - 开发实现时的标准遵循
Enforces C++ Core Guidelines for writing, reviewing, and refactoring modern C++ (C++17/20/23) code, promoting RAII, immutability, type safety, and value semantics.
Applies C++ Core Guidelines to write, review, or refactor C++ code. Enforces modern, safe, and idiomatic practices for C++17/20/23.
Share bugs, ideas, or general feedback.
| 场景 | Skill | 说明 |
|---|---|---|
| 内存管理 | Skills(c:memory) | 分配、泄漏检测、对齐 |
| 并发编程 | Skills(c:concurrency) | 原子操作、线程、锁 |
| 错误处理 | Skills(c:error) | errno、goto cleanup、安全字符串 |
| POSIX API | Skills(c:posix) | 文件、进程、信号、网络 |
| 嵌入式 | Skills(c:embedded) | 寄存器、中断、MISRA |
| AI 理性化 | 实际检查 |
|---|---|
| "用 GCC 扩展更方便" | 是否用了标准 C 替代方案? |
| "不需要 static_assert" | 是否有编译期可验证的假设? |
| "这个隐式转换没问题" | 是否有截断或符号问题? |
| "不需要 const" | 参数是否被修改? |
| "CMake 太复杂用 Makefile" | 项目是否需要跨平台构建? |
| 特性 | 关键字/语法 | 用途 |
|---|---|---|
| 泛型选择 | _Generic | 类型安全宏 |
| 静态断言 | _Static_assert / static_assert | 编译期检查 |
| 匿名结构/联合 | 无名 struct/union 成员 | 简化嵌套访问 |
| 对齐控制 | _Alignas / _Alignof | 内存对齐 |
| 无返回 | _Noreturn | 标记不返回函数 |
| 线程局部 | _Thread_local | 线程私有变量 |
| 原子操作 | _Atomic / <stdatomic.h> | 无锁并发 |
| 特性 | 语法 | 说明 |
|---|---|---|
| nullptr | nullptr | 替代 NULL,类型安全空指针 |
| constexpr | constexpr int N = 42; | 编译期常量 |
| typeof | typeof(expr) | 标准化类型推导 |
| auto | auto x = expr; | 类型推导(仅局部变量) |
| #embed | #embed "data.bin" | 二进制数据嵌入 |
| [[nodiscard]] | [[nodiscard]] int func(); | 返回值不可忽略 |
| [[maybe_unused]] | [[maybe_unused]] int x; | 抑制未使用警告 |
| [[deprecated]] | [[deprecated("use v2")]] | 标记废弃 |
cmake_minimum_required(VERSION 3.28)
project(myproject C)
set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
add_compile_options(-Wall -Wextra -Werror -pedantic)
# Sanitizer 支持
option(ENABLE_SANITIZERS "Enable ASan+UBSan" OFF)
if(ENABLE_SANITIZERS)
add_compile_options(-fsanitize=address,undefined -fno-omit-frame-pointer)
add_link_options(-fsanitize=address,undefined)
endif()
# clang-tidy(推荐配置 .clang-tidy 文件)
clang-tidy src/*.c -- -std=c17
# cppcheck
cppcheck --enable=all --std=c17 --error-exitcode=1 src/
# 编译器所有警告
gcc -std=c17 -Wall -Wextra -Werror -pedantic -Wshadow \
-Wconversion -Wdouble-promotion -Wformat=2
// C11 泛型选择
#define abs_val(x) _Generic((x), \
int: abs, \
long: labs, \
float: fabsf, \
double: fabs \
)(x)
// C11 静态断言
static_assert(sizeof(int) >= 4, "int must be at least 32-bit");
static_assert(_Alignof(double) == 8, "double alignment check");
// 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
-std=c17 编译,零警告零错误