From ultrapowers-dev
Use when writing or reviewing C/C++ code. Covers memory management, RAII, smart pointers, const correctness, CMake, sanitizers, and common undefined behavior pitfalls.
How this skill is triggered — by the user, by Claude, or both
Slash command
/ultrapowers-dev:c-cpp-best-practicesThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
C gives you full control; C++ gives you abstractions to manage that control safely. In both, every allocation must have an owner and every pointer must have a valid target.
C gives you full control; C++ gives you abstractions to manage that control safely. In both, every allocation must have an owner and every pointer must have a valid target.
malloc with free. Use a single owner convention -- whoever allocates is responsible for freeing.new/delete directly in application code.std::unique_ptr for sole ownership, std::shared_ptr only when ownership is genuinely shared. Avoid std::shared_ptr as a default.const unless mutation is intended: void process(const std::string& input).const when they do not modify state.const pointers: const char* str (pointer to const data) vs char* const ptr (const pointer).| Tool | Purpose |
|---|---|
| CMake | Build system -- use target_* commands, avoid global settings |
clang-tidy | Static analysis -- enable modernize-*, bugprone-*, cppcoreguidelines-* |
| AddressSanitizer | Runtime detection of buffer overflows, use-after-free (-fsanitize=address) |
Valgrind / memcheck | Memory leak detection, uninitialised reads |
clang-format | Code formatting -- enforce in CI |
| Pitfall | Fix |
|---|---|
| Buffer overflow (out-of-bounds write) | Use std::vector/std::array (C++), bounds-check in C, enable ASan |
| Dangling pointer / use-after-free | RAII + smart pointers; never return pointers to locals |
| Undefined behavior (signed overflow, null deref) | Enable -fsanitize=undefined, test with UBSan |
| Memory leaks | Valgrind in CI, RAII in C++, cleanup functions in C |
| Missing virtual destructor (C++) | Always declare virtual ~Base() = default for polymorphic base classes |
Raw new/delete in modern C++ | Use std::make_unique / std::make_shared exclusively |
Original -- Datatide, MIT licensed.
npx claudepluginhub ennio-datatide/ultrapowers-devEnforces C++ Core Guidelines for writing, reviewing, and refactoring modern C++ code (C++17+), promoting RAII, immutability, type safety, and idiomatic practices.
Applies C++ Core Guidelines to write, review, or refactor C++ code. Enforces modern, safe, and idiomatic practices for C++17/20/23.
Writes modern C++ code with RAII, smart pointers, STL algorithms, templates, move semantics, and concurrency. Provides CMake, sanitizers, benchmarks, and unit tests.