C/C++ Cursor Rules: Systems Programming Configuration

Cursor rules for C and C++ development covering memory management, STL usage, RAII patterns, and modern C++ standards for systems-level programming.

August 20, 2024by PromptGenius Team
c++ccursor-rulessystems-programmingmemory-management

Overview

C and C++ are the backbone of performance-critical applications, from operating systems to game engines and embedded devices. These cursor rules enforce modern C++17+ standards, RAII (Resource Acquisition Is Initialization) patterns, and smart pointer usage to help AI assistants generate memory-safe, efficient code. Whether you're building a low-latency trading system or an embedded controller, these rules ensure your codebase remains maintainable while maximizing bare-metal performance.

Note:

Enforces C++17+ features, smart pointer usage, constexpr patterns, and STL best practices for production-ready systems programming.

Rules Configuration

---
description: Enforces best practices for C/C++ development, focusing on modern standards, RAII, smart pointers, and STL patterns. Provides comprehensive guidelines for writing memory-safe, performant systems code with proper context.
globs: **/*.{c,cpp,h,hpp}
---
# C/C++ Best Practices

You are an expert in C/C++ development and systems programming.
You understand modern C/C++ development practices, memory management patterns, and the importance of providing complete context in code generation.

### Code Style
- 4 spaces indentation
- snake_case for functions/variables
- PascalCase for types/classes
- SCREAMING_SNAKE_CASE for macros
- 100 char line limit

### Best Practices
- Use modern C++ (C++17+)
- Prefer smart pointers over raw pointers
- Use RAII for resource management
- Use std::vector over raw arrays
- Use std::optional for nullable values
- Prefer constexpr for compile-time

### AI Instructions
- Include necessary headers
- Use forward declarations when possible
- Provide CMakeLists.txt for build
- Add Google Test or Catch2 tests
- Comment complex logic

Installation

Create cpp.mdc in your project's .cursor/rules/ directory and paste the configuration above. Cursor and Windsurf both read .cursor/rules/ — Copilot users place it in .github/copilot-instructions.md instead.

Examples

// smart_ptr_example.cpp — RAII with smart pointers and modern C++
#include <memory>
#include <vector>

class Widget {
    std::unique_ptr<Resource> resource_;
public:
    explicit Widget(std::unique_ptr<Resource> res)
        : resource_(std::move(res)) {}

    void process() {
        if (resource_) resource_->execute();
    }
};

// Factory function returning smart pointer
auto make_widget() -> std::unique_ptr<Widget> {
    auto res = std::make_unique<Resource>();
    return std::make_unique<Widget>(std::move(res));
}