modern-c-dev
Purpose
This skill provides practical guidance for modern C language engineering tasks,
sourced from the comprehensive "你所不知道的 C 語言" (Things You Don't Know About C)
lecture series by sysprog.
It also fuses an external tutorial-based route map for practice, basics, and expertise progression.
Quick Reference Index
| Topic |
File |
When to Use |
| Bitwise Operations |
references/01-bitwise-operations.md |
Bit manipulation, flags, masks |
| Floating Point |
references/02-floating-point.md |
FP precision, IEEE 754, NaN/Inf |
| C Intro |
references/03-c-programming-intro.md |
Language overview |
| C Deep Dive |
references/04-c-deep-dive.md |
Advanced concepts |
| CRT |
references/05-c-runtime-library.md |
Runtime library internals |
| C Standards |
references/06-c-standards.md |
C99/C11/C17 differences |
| Stream I/O |
references/07-stream-io.md |
EOF handling, buffering |
| Undefined Behavior |
references/08-undefined-behavior.md |
UB detection and avoidance |
| Control Flow |
references/09-goto-control-flow.md |
goto, switch, coroutines |
| Server Framework |
references/10-server-framework.md |
Network programming patterns |
| Encoding/DS |
references/11-character-encoding-data-structures.md |
UTF-8, data structures |
| Memory Management |
references/12-memory-management-alignment.md |
malloc, alignment, cache |
| Compiler Principles |
references/13-compiler-principles.md |
Compiler internals |
| OOP in C |
references/14-oop-in-c.md |
Object-oriented patterns |
| Dynamic Linker |
references/15-dynamic-linker.md |
dlopen, dlsym, PLT/GOT |
| Tips & Tricks |
references/17-c-tips-and-tricks.md |
Idioms and techniques |
| Preprocessor |
references/18-preprocessor.md |
Macros, conditional compilation |
| Pointers |
references/19-pointers.md |
Pointer arithmetic, void* |
| Function Calling |
references/20-function-calling.md |
ABI, stack frame, calling conventions |
| Compiler Optimization |
references/21-compiler-optimization.md |
Optimization flags, techniques |
| Linker & ELF |
references/22-linker-elf.md |
Linking, ELF format |
| Linked Lists |
references/23-linked-list-memory.md |
List operations, memory |
| External C Route Map |
references/c-tutorial-route-map.md |
Learning progression and topic routing |
| External C Essence |
references/c-tutorial-essence.md |
Distilled actionable rules for answers |
Fusion Strategy (sysprog + external tutorial)
Use both sources together:
- Use sysprog references for deep implementation-level detail.
- Use external route map for pedagogical sequencing and issue triage.
- Start from topic classification (
practice, basics, expertise), then jump to the strongest sysprog reference.
Recommended response order:
- Classify the user's request into topic bucket(s).
- Give a compact conceptual explanation.
- Provide a minimal compilable C example.
- Add a risk checklist (UB, lifetime, conversion, side effects).
- Point to one route-map topic and one sysprog reference for follow-up.
External Topic Router
Routing references:
references/c-tutorial-route-map.md
references/c-tutorial-essence.md
When users ask these, prioritize external mapping first:
- Beginner mistakes, debugging process, asking for help, coding style, naming
- Function/types/I-O/type conversion
- Declaration vs definition, scope/lifetime, dynamic allocation
- C standard differences, UB/unspecified behavior, lvalue/rvalue
- Array vs pointer, memory layout, struct details, side effects in subexpressions
Task Routing Guide
Memory & Pointer Issues
- Pointer bugs:
references/19-pointers.md
- Memory management:
references/12-memory-management-alignment.md
- Linked lists:
references/23-linked-list-memory.md
Compilation & Toolchain
- Compiler warnings/errors:
references/13-compiler-principles.md, references/21-compiler-optimization.md
- Linker issues:
references/22-linker-elf.md, references/15-dynamic-linker.md
- Preprocessor macros:
references/18-preprocessor.md
Code Safety & UB
- Undefined behavior:
references/08-undefined-behavior.md
- Safety checklist: Cross-reference
08-undefined-behavior.md and 19-pointers.md
Performance & Optimization
- Bitwise operations:
references/01-bitwise-operations.md
- Compiler optimizations:
references/21-compiler-optimization.md
- Memory alignment:
references/12-memory-management-alignment.md
Control Flow & Design
- goto/switch patterns:
references/09-goto-control-flow.md
- OOP patterns in C:
references/14-oop-in-c.md
- Function calling:
references/20-function-calling.md
I/O & Encoding
- Stream I/O:
references/07-stream-io.md
- Character encoding:
references/11-character-encoding-data-structures.md
C Programming Techniques
Safe goto Patterns (from 09-goto-control-flow.md)
Use goto for centralized error handling:
int process_data() {
void *buffer = NULL;
FILE *fp = NULL;
int status = -1;
buffer = malloc(BUF_SIZE);
if (!buffer) goto cleanup;
fp = fopen("data.txt", "r");
if (!fp) goto cleanup;
// ... process data ...
status = 0;
cleanup:
if (fp) fclose(fp);
free(buffer);
return status;
}
Duff's Device (Loop Unrolling)
void copy(char *to, char *from, int count) {
int n = (count + 7) / 8;
switch (count % 8) {
case 0: do { *to++ = *from++;
case 7: *to++ = *from++;
case 6: *to++ = *from++;
case 5: *to++ = *from++;
case 4: *to++ = *from++;
case 3: *to++ = *from++;
case 2: *to++ = *from++;
case 1: *to++ = *from++;
} while (--n > 0);
}
}
Multi-line Macro Safety
Always wrap multi-line macros in do { ... } while (0):
#define SAFE_FREE(ptr) do { \
free(ptr); \
(ptr) = NULL; \
} while (0)
Container_of Macro (OOP in C)
#define container_of(ptr, type, member) ({ \
const typeof(((type *)0)->member) *__mptr = (ptr); \
(type *)((char *)__mptr - offsetof(type, member)); \
})
Output Style Guidelines
When answering C programming questions:
- Explain assumptions - State what you're assuming about the platform (32/64-bit, endianness)
- Distinguish spec vs implementation - Clarify what's guaranteed by C standard vs compiler-specific
- Provide minimal examples - Show concise, compilable code snippets
- Include risk notes - Warn about UB, aliasing, alignment, and overflow
- Reference sources - Point to specific reference files for deep dives
Common Pitfalls
Undefined Behavior to Avoid
- Signed integer overflow
- Null pointer dereference
- Array bounds violation
- Strict aliasing violations
- Uninitialized variable use
Safe Practices
- Use
size_t for sizes and indices
- Check malloc return values
- Prefer
const correctness
- Initialize all variables
- Use static analysis tools
Scripts (Optional)
The scripts/ directory may contain helper scripts:
find-pattern.sh - Search for C idioms across the references
extract-examples.sh - Extract code examples from reference files
To use scripts:
cd /home/ares/yyskills/output/modern-c-dev
./scripts/find-pattern.sh "Duff's Device"
1---2name: modern-c-dev3description: Claude-optimized modern C skill from sysprog c-prog notes. This skill also integrates an external structured C tutorial route map for practical learning and debugging workflows. Use this skill for modern C language engineering tasks, especially when you need: - Memory management, pointer manipulation, and alignment guidance - Compiler toolchain behavior, optimization, and ABI understanding - Undefined behavior analysis and safety checklists - Low-level optimization and bitwise operations - Function calling conventions and control flow patterns - Stream I/O, EOF handling, and error patterns - Object-oriented design patterns in C - Preprocessor techniques and macro safety - Dynamic linking and ELF format understanding - Linked list and non-contiguous memory operations - Beginner-to-advanced C learning paths and problem diagnosis patterns Trigger this skill whenever the user mentions C programming, memory issues, pointer bugs, compiler warnings, undefined behavior, or low-level system programming.4---56# modern-c-dev78## Purpose910This skill provides practical guidance for modern C language engineering tasks,11sourced from the comprehensive "你所不知道的 C 語言" (Things You Don't Know About C)12lecture series by sysprog.13It also fuses an external tutorial-based route map for practice, basics, and expertise progression.1415## Quick Reference Index1617| Topic | File | When to Use |18|-------|------|-------------|19| Bitwise Operations | `references/01-bitwise-operations.md` | Bit manipulation, flags, masks |20| Floating Point | `references/02-floating-point.md` | FP precision, IEEE 754, NaN/Inf |21| C Intro | `references/03-c-programming-intro.md` | Language overview |22| C Deep Dive | `references/04-c-deep-dive.md` | Advanced concepts |23| CRT | `references/05-c-runtime-library.md` | Runtime library internals |24| C Standards | `references/06-c-standards.md` | C99/C11/C17 differences |25| Stream I/O | `references/07-stream-io.md` | EOF handling, buffering |26| Undefined Behavior | `references/08-undefined-behavior.md` | UB detection and avoidance |27| Control Flow | `references/09-goto-control-flow.md` | goto, switch, coroutines |28| Server Framework | `references/10-server-framework.md` | Network programming patterns |29| Encoding/DS | `references/11-character-encoding-data-structures.md` | UTF-8, data structures |30| Memory Management | `references/12-memory-management-alignment.md` | malloc, alignment, cache |31| Compiler Principles | `references/13-compiler-principles.md` | Compiler internals |32| OOP in C | `references/14-oop-in-c.md` | Object-oriented patterns |33| Dynamic Linker | `references/15-dynamic-linker.md` | dlopen, dlsym, PLT/GOT |34| Tips & Tricks | `references/17-c-tips-and-tricks.md` | Idioms and techniques |35| Preprocessor | `references/18-preprocessor.md` | Macros, conditional compilation |36| Pointers | `references/19-pointers.md` | Pointer arithmetic, void* |37| Function Calling | `references/20-function-calling.md` | ABI, stack frame, calling conventions |38| Compiler Optimization | `references/21-compiler-optimization.md` | Optimization flags, techniques |39| Linker & ELF | `references/22-linker-elf.md` | Linking, ELF format |40| Linked Lists | `references/23-linked-list-memory.md` | List operations, memory |41| External C Route Map | `references/c-tutorial-route-map.md` | Learning progression and topic routing |42| External C Essence | `references/c-tutorial-essence.md` | Distilled actionable rules for answers |4344## Fusion Strategy (sysprog + external tutorial)4546Use both sources together:47- Use sysprog references for deep implementation-level detail.48- Use external route map for pedagogical sequencing and issue triage.49- Start from topic classification (`practice`, `basics`, `expertise`), then jump to the strongest sysprog reference.5051Recommended response order:521. Classify the user's request into topic bucket(s).532. Give a compact conceptual explanation.543. Provide a minimal compilable C example.554. Add a risk checklist (UB, lifetime, conversion, side effects).565. Point to one route-map topic and one sysprog reference for follow-up.5758## External Topic Router5960Routing references:61- `references/c-tutorial-route-map.md`62- `references/c-tutorial-essence.md`6364When users ask these, prioritize external mapping first:65- Beginner mistakes, debugging process, asking for help, coding style, naming66- Function/types/I-O/type conversion67- Declaration vs definition, scope/lifetime, dynamic allocation68- C standard differences, UB/unspecified behavior, lvalue/rvalue69- Array vs pointer, memory layout, struct details, side effects in subexpressions7071## Task Routing Guide7273### Memory & Pointer Issues74- **Pointer bugs**: `references/19-pointers.md`75- **Memory management**: `references/12-memory-management-alignment.md`76- **Linked lists**: `references/23-linked-list-memory.md`7778### Compilation & Toolchain79- **Compiler warnings/errors**: `references/13-compiler-principles.md`, `references/21-compiler-optimization.md`80- **Linker issues**: `references/22-linker-elf.md`, `references/15-dynamic-linker.md`81- **Preprocessor macros**: `references/18-preprocessor.md`8283### Code Safety & UB84- **Undefined behavior**: `references/08-undefined-behavior.md`85- **Safety checklist**: Cross-reference `08-undefined-behavior.md` and `19-pointers.md`8687### Performance & Optimization88- **Bitwise operations**: `references/01-bitwise-operations.md`89- **Compiler optimizations**: `references/21-compiler-optimization.md`90- **Memory alignment**: `references/12-memory-management-alignment.md`9192### Control Flow & Design93- **goto/switch patterns**: `references/09-goto-control-flow.md`94- **OOP patterns in C**: `references/14-oop-in-c.md`95- **Function calling**: `references/20-function-calling.md`9697### I/O & Encoding98- **Stream I/O**: `references/07-stream-io.md`99- **Character encoding**: `references/11-character-encoding-data-structures.md`100101## C Programming Techniques102103### Safe goto Patterns (from `09-goto-control-flow.md`)104105Use goto for centralized error handling:106107```c108int process_data() {109 void *buffer = NULL;110 FILE *fp = NULL;111 int status = -1;112113 buffer = malloc(BUF_SIZE);114 if (!buffer) goto cleanup;115116 fp = fopen("data.txt", "r");117 if (!fp) goto cleanup;118119 // ... process data ...120 status = 0;121122cleanup:123 if (fp) fclose(fp);124 free(buffer);125 return status;126}127```128129### Duff's Device (Loop Unrolling)130131```c132void copy(char *to, char *from, int count) {133 int n = (count + 7) / 8;134 switch (count % 8) {135 case 0: do { *to++ = *from++;136 case 7: *to++ = *from++;137 case 6: *to++ = *from++;138 case 5: *to++ = *from++;139 case 4: *to++ = *from++;140 case 3: *to++ = *from++;141 case 2: *to++ = *from++;142 case 1: *to++ = *from++;143 } while (--n > 0);144 }145}146```147148### Multi-line Macro Safety149150Always wrap multi-line macros in `do { ... } while (0)`:151152```c153#define SAFE_FREE(ptr) do { \154 free(ptr); \155 (ptr) = NULL; \156} while (0)157```158159### Container_of Macro (OOP in C)160161```c162#define container_of(ptr, type, member) ({ \163 const typeof(((type *)0)->member) *__mptr = (ptr); \164 (type *)((char *)__mptr - offsetof(type, member)); \165})166```167168## Output Style Guidelines169170When answering C programming questions:1711721. **Explain assumptions** - State what you're assuming about the platform (32/64-bit, endianness)1732. **Distinguish spec vs implementation** - Clarify what's guaranteed by C standard vs compiler-specific1743. **Provide minimal examples** - Show concise, compilable code snippets1754. **Include risk notes** - Warn about UB, aliasing, alignment, and overflow1765. **Reference sources** - Point to specific reference files for deep dives177178## Common Pitfalls179180### Undefined Behavior to Avoid181- Signed integer overflow182- Null pointer dereference183- Array bounds violation184- Strict aliasing violations185- Uninitialized variable use186187### Safe Practices188- Use `size_t` for sizes and indices189- Check malloc return values190- Prefer `const` correctness191- Initialize all variables192- Use static analysis tools193194## Scripts (Optional)195196The `scripts/` directory may contain helper scripts:197198- `find-pattern.sh` - Search for C idioms across the references199- `extract-examples.sh` - Extract code examples from reference files200201To use scripts:202```bash203cd /home/ares/yyskills/output/modern-c-dev204./scripts/find-pattern.sh "Duff's Device"205```