A minimal C project template with CMake build system and VSCode devcontainer.
- Simple C program with standard directory structure
- CMake build system configured for C17 standard
- Clang compiler with clangd for enhanced IntelliSense
- VSCode devcontainer with Docker
- Essential C development tools pre-installed
- Open this project in VSCode
- When prompted, click "Reopen in Container" or use Command Palette:
Dev Containers: Reopen in Container - The container will automatically build the project
- Run the program:
./build/bin/hello_world
. βββ .devcontainer/ β βββ devcontainer.json # VSCode devcontainer configuration β βββ Dockerfile # Docker image definition β βββ GIT_SETUP.md # Git setup documentation β βββ setup-git.sh # Git configuration setup script βββ src/ β βββ main.c # Main C source file βββ build/ # Build output directory β βββ debug/ # Debug build artifacts β βββ bin/ # Debug executables β βββ ... # CMake build files βββ .clang-format # Code formatting configuration βββ .clang-tidy # Static analysis configuration βββ .clangd # Language server configuration βββ CMakeLists.txt # CMake build configuration βββ CMakePresets.json # CMake preset configurations βββ GITHUB_ACTIONS_GUIDE.md # GitHub Actions CI documentation βββ VALGRIND_GUIDE.md # Valgrind memory debugging guide βββ .gitignore # Git ignore rules βββ README.md # This file # Build debug and run immediately cmake --preset debug && cmake --build --preset run-debug # Build release and run immediately cmake --preset release && cmake --build --preset run-release# Debug build cmake --preset debug cmake --build --preset debug ./build/debug/bin/hello_world # Release build cmake --preset release cmake --build --preset release ./build/release/bin/hello_worldmkdir build cd build cmake .. make ./bin/hello_worldThe project includes comprehensive code quality configurations:
- LLVM-based style with C-specific adjustments
- 4-space indentation with Linux brace style
- 100-character line limit for readability
- Automatic include sorting and formatting
- C-focused static analysis checks
- Bug detection and performance analysis
- Code style enforcement with snake_case naming
- Security checks (CERT guidelines)
- C17 standard support with background indexing
- Inlay hints for parameters and types
- Integration with clang-format and clang-tidy
These tools provide:
- Real-time code formatting and linting
- Advanced code completion and navigation
- Static analysis and bug detection
- Consistent code style enforcement
- Clang compiler (C17 standard) with maximum optimization for release builds
- Clangd language server for enhanced IntelliSense and code analysis
- Clang-tidy for static analysis and code quality checks
- CMake build system with automatic configuration
- LLDB debugger for debugging (integrated with clangd)
- Valgrind memory checker for detecting leaks, buffer overflows, and memory errors
- Git with SSH signing support
- Docker extension for container management
- VSCode extensions: clangd, CMake Tools, Docker, CodeLLDB, GitHub Actions
- Optimization:
-O0(no optimization for easier debugging) - Debug symbols:
-g(full debugging information) - Warnings:
-Wall -Wextra(comprehensive warning detection) - Size: ~17KB (with debug symbols)
- Optimization:
-O3(maximum speed optimization) - Link-time optimization:
-flto(whole-program optimization) - CPU-specific:
-march=native -mtune=native(optimized for current CPU) - Math optimization:
-ffast-math(aggressive floating-point optimizations) - Loop optimization:
-funroll-loops(unroll loops for speed) - Frame pointer:
-fomit-frame-pointer(smaller, faster code) - Dead code elimination:
-Wl,--gc-sections(remove unused code) - Symbol stripping:
-Wl,--strip-all(remove debug symbols) - Size: ~15KB (highly optimized)
The project is configured for debugging with LLDB (Low Level Debugger) which integrates seamlessly with clangd:
- Set breakpoints by clicking in the gutter next to line numbers
- Press F5 or go to Run and Debug panel
- Select debug configuration:
- "Debug with LLDB" (debug build)
- Breakpoints and step-through debugging
- Variable inspection and watch expressions
- Call stack navigation
- Integrated terminal for LLDB commands
- Automatic build before debugging
# Build debug version cmake --preset debug && cmake --build --preset debug # Debug with LLDB lldb build/debug/bin/hello_world (lldb) breakpoint set --name main (lldb) runValgrind is integrated for detecting memory leaks, buffer overflows, and other memory issues:
# Basic memory check valgrind ./build/debug/bin/hello_world # Full memory check with leak detection valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./build/debug/bin/hello_world # Cache profiling valgrind --tool=cachegrind ./build/debug/bin/hello_world- Press
Ctrl+Shift+Pβ "Tasks: Run Task" β "valgrind-check" - Or use the terminal:
valgrind --leak-check=full ./build/debug/bin/hello_world
- Memory leaks (allocated but never freed)
- Buffer overflows (writing beyond allocated memory)
- Use after free (accessing freed memory)
- Double free (freeing the same memory twice)
- Uninitialized memory access
See VALGRIND_GUIDE.md for comprehensive usage instructions.
The project includes comprehensive documentation for various development workflows:
- CI/CD workflow setup and configuration
- GitHub Actions integration and automation
- Build pipeline management and troubleshooting
- Artifact handling and deployment strategies
- Memory debugging with Valgrind Memcheck
- Performance profiling with Cachegrind
- Memory leak detection and analysis
- Advanced Valgrind usage patterns and tips
- Git configuration setup in dev containers
- SSH key management and commit signing
- Troubleshooting common Git issues
- Security best practices for development
| Guide | Purpose | When to Use |
|---|---|---|
GITHUB_ACTIONS_GUIDE.md | CI/CD workflows | Setting up automated builds and testing |
VALGRIND_GUIDE.md | Memory debugging | Finding memory leaks and performance issues |
GIT_SETUP.md | Git configuration | Troubleshooting Git setup in containers |
The project includes a comprehensive clang-tidy configuration (.clang-tidy) with 200+ checks:
- Buffer overflows and null pointer dereferences
- Memory leaks and use-after-free detection
- Infinite loops and suspicious conditions
- Macro issues and string handling problems
- Narrowing conversions and type safety
- Inefficient loops and unnecessary copies
- Move semantics and copy optimization
- Type promotions in math functions
- Automatic move detection
- Function complexity (max 20 cognitive complexity)
- Function size (max 50 lines)
- Identifier naming (min 3 characters)
- Code formatting and brace usage
- Magic numbers detection
- Deprecated functions detection
- Loop conversion suggestions
- Auto keyword usage
- Nullptr instead of NULL
- Override keyword usage
- Buffer overflow prevention
- Integer overflow detection
- Unsafe functions warnings
- Memory management issues
# Basic analysis clang-tidy src/main.c -- -Ibuild/debug -std=c17 # With specific checks clang-tidy -checks='bugprone-*,performance-*' src/main.c -- -Ibuild/debug -std=c17- Real-time analysis with clangd extension
- Error highlighting in editor
- Quick fixes for common issues
- Hover information for warnings
- Automated analysis on every commit
- Error reporting in pull requests
- Artifact upload for detailed reports
The .clang-tidy file includes:
- 200+ enabled checks across all categories
- Custom thresholds for complexity and size
- Naming conventions for identifiers
- Performance warnings configuration
- Excluded checks for C++-specific rules
src/main.c:30:9: warning: variable name 'i' is too short, expected at least 3 characters [readability-identifier-length] src/main.c:31:5: warning: kernel performance could be improved by unrolling this loop [altera-unroll-loops] src/main.c:39:19: warning: parameter name 'a' is too short [readability-identifier-length] src/main.c:41:19: warning: statement should be inside braces [readability-braces-around-statements] src/main.c:51:30: warning: narrowing conversion from 'unsigned long' to signed type 'int' [bugprone-narrowing-conversions] The project includes a comprehensive GitHub Actions CI workflow that runs on every push and pull request:
- Debug build with full debugging symbols
- Release build with maximum optimization
- Parallel builds using all available CPU cores
- clang-tidy with comprehensive checks (200+ rules)
- Bug detection (buffer overflows, null pointer derefs, etc.)
- Performance analysis (inefficient loops, unnecessary copies)
- Code style enforcement (naming, formatting, complexity)
- Modern C practices (deprecated functions, best practices)
- C17 standard compliance verification
- Warning detection with
-Wall -Wextra
- Valgrind Memcheck for memory leak detection
- Valgrind Cachegrind for performance profiling
- Both debug and release builds tested
- Build artifacts uploaded for inspection
- Valgrind reports preserved for analysis
- 7-day retention for debugging failed builds
- Push to
mainormasterbranch - Pull requests targeting
mainormasterbranch
- Real-time workflow status in the sidebar
- Pinned workflows for quick access
- Log viewing directly in VS Code
- Workflow management and re-running
- Artifact download from the editor
- Go to your GitHub repository
- Click on "Actions" tab
- Select the workflow run
- Download artifacts for detailed analysis
The dev container includes the GitHub Actions extension with:
- Pin workflows for quick access
- View workflow status in real-time
- Re-run failed workflows with one click
- Cancel running workflows when needed
- View logs directly in VS Code
- Syntax highlighting for YAML workflows
- Error highlighting and navigation
- Step-by-step execution tracking
- Download artifacts from VS Code
- Browse build outputs without leaving the editor
- Valgrind reports accessible locally
- Build artifacts inspection
- Edit workflows with IntelliSense
- Validate YAML syntax
- Quick actions for common tasks
- Integration with Git operations