目录 / C
C
--- name: C slug: c version: 1.0.1 description: Write safe C avoiding memory corruption, buffer overflows, and undefined behavior traps. metadata: {"clawdbot":{"emoji":"⚙️","requires":{"bins":["gcc","clang"]},"os":["linux","darwin","win32"]}} --- ## Quick Reference | Topic | File | |-------|------| | malloc/free, leaks, double free | `memory.md` | | Null, dangling, pointer arithmetic | `pointers.md` | | Null terminator, buffer overflow | `strings.md` | | Integer overflow, signed/unsigned | `types.md` | | Macro traps, include guards | `preprocessor.md` | | Common undefined behavior | `undefined.md` | ## Critical Rules - `malloc` returns `void*` — cast required in C++, optional in C but check for NULL - `free(ptr); ptr = NULL;` — always null after free to prevent double-free - `sizeof(array)` in function gives pointer size, not array size — pass length separately - `char str[5] = "hello";` — no room for null terminator, UB when used as string - `strcpy` doesn't check bounds — use `strncpy` and manually null-terminate - Signed overflow is UB — compiler can optimize assuming it never happens - `i++ + i++` is UB — no sequence point between modifications - Returning pointer to local variable — dangling pointer, UB on use - `#define SQUARE(x) x*x` — `SQUARE(1+2)` = `1+2*1+2` = 5, not 9 - `memcpy` with overlapping regions — use `memmove` instead - Uninitialized variables — contain garbage, UB if used - Array out of bounds — no runtime check, silent corruption or crash
这是模型对公开材料的总结,不是官方声明,请以原链内容为准。
存档时间线
| 版本 | 存档时间 | 内容哈希 | 内容 |
|---|---|---|---|
| v5 | 2026-09-28 17:52 | bd1807d1 | 已过保留期 |
| v6 | 2026-09-29 02:32 | e6de2314 | 已过保留期 |
| v7 | 2026-09-28 21:28 | bd1807d1 | 已过保留期 |
| v8 | 2026-09-29 12:07 | e6de2314 | 已过保留期 |
| v9 | 2026-09-29 16:22 | bd1807d1 | 已过保留期 |
| v10 | 2026-09-30 04:11 | e6de2314 | 已过保留期 |
| v11 | 2026-09-30 11:27 | bd1807d1 | 已过保留期 |
| v12 | 2026-09-30 23:34 | e6de2314 | 已过保留期 |
| v13 | 2026-10-01 06:32 | bd1807d1 | 已过保留期 |
| v14 | 2026-10-01 18:15 | e6de2314 | 可取 |
版本索引永久保留;内容副本只保留最新 1 份,更早版本仅留索引与哈希(存档时间线的证据链不会因此断裂)。
提交举报 / 纠错
侵权举报经核验成立后,我们会即时下线该条目并删除已存的内容副本。