# C Cpp Compilers

> C and C++ compiler toolchain skill covering GCC, Clang/LLVM, build modes, warnings, sanitizers, static analysis, LTO, PGO, C++20/23/26 features, and debugging. Use when writing or reviewing C/C++ code, choosing compiler flags, interpreting errors or warnings, enabling sanitizers, running clang-tidy or cppcheck, optimizing builds, working with C++20 modules or C23 features, or troubleshooting link…

- **Type:** Skill
- **Install:** `agentstack add skill-kaynetik-skills-c-cpp-compilers`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [kaynetik](https://agentstack.voostack.com/s/kaynetik)
- **Installs:** 0
- **Category:** [Developer Tools](https://agentstack.voostack.com/c/developer-tools)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [kaynetik](https://github.com/kaynetik)
- **Source:** https://github.com/kaynetik/skills/tree/main/c-cpp-compilers

## Install

```sh
agentstack add skill-kaynetik-skills-c-cpp-compilers
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# C/C++ Compilers

Guidance for compiling, analyzing, and optimizing C and C++ code with GCC and Clang in 2026.

## Reference files

- **GCC specifics**: [gcc.md](reference/gcc.md) -- flags, diagnostics, PGO, LTO, error triage
- **Clang specifics**: [clang.md](reference/clang.md) -- diagnostics, optimization remarks, clang-tidy, macOS
- **Sanitizers**: [sanitizers.md](reference/sanitizers.md) -- ASan, UBSan, TSan, MSan, LSan decision tree and reports
- **Static analysis**: [static-analysis.md](reference/static-analysis.md) -- clang-tidy, cppcheck, scan-build, CI integration
- **Modern C/C++**: [modern-cpp.md](reference/modern-cpp.md) -- C++20 modules, C++23/26 features, C23, migration

## Standards baseline (2026)

| Language | Preferred standard | GCC support | Clang support |
|----------|--------------------|-------------|---------------|
| C | `-std=c23` (or `-std=c17` for broad compat) | GCC 15+ | Clang 18+ |
| C++ | `-std=c++23` (or `-std=c++20` minimum) | GCC 14+ | Clang 18+ |

Always pass the standard flag explicitly. Never rely on compiler defaults.

## Build modes

| Goal | Flags |
|------|-------|
| Debug | `-g -O0 -Wall -Wextra -Wpedantic` |
| Debug (GDB-friendly optimized) | `-g -Og -Wall -Wextra` |
| Release | `-O2 -DNDEBUG -Wall` |
| Release (max throughput, native) | `-O3 -march=native -DNDEBUG -flto` |
| Release (min binary size) | `-Os -DNDEBUG` (Clang: `-Oz`) |
| Sanitizer build | `-g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer` |

## Warning discipline

Start with `-Wall -Wextra -Wpedantic`. Add `-Werror` in CI.

Suppress narrow scopes only:

```c
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
void callback(int ctx, int unused) { (void)ctx; }
#pragma GCC diagnostic pop
```

Clang equivalent works the same. For project-wide suppression, prefer `.clang-tidy` config or `-Wno-` in build system, not in source.

## Optimization decision tree

```
Need max throughput on known hardware?
  yes -> -O3 -march=native -flto
  no  -> Have profiling data?
           yes -> -O2 -fprofile-use (GCC) / -fprofile-instr-use (Clang)
           no  -> -O2

Size-constrained (embedded, shared lib)?
  yes -> -Os (GCC/Clang) or -Oz (Clang only)

Numerical code that tolerates IEEE relaxation?
  yes -> -Ofast (enables -ffast-math; breaks NaN/inf handling)
  no  -> stay with -O2/-O3
```

`-O3` vs `-O2`: `-O3` adds aggressive loop transforms and wider inlining. Benchmark before committing -- i-cache pressure can cause regressions.

## LTO

```bash
# GCC
gcc -O2 -flto=auto -c foo.c bar.c
gcc -O2 -flto=auto foo.o bar.o -o prog

# Clang (ThinLTO preferred for large projects)
clang -O2 -flto=thin -fuse-ld=lld -c foo.c bar.c
clang -O2 -flto=thin -fuse-ld=lld foo.o bar.o -o prog
```

Use `gcc-ar` / `gcc-ranlib` for GCC LTO archives. Clang ThinLTO links 5-10x faster than full LTO with comparable code quality.

## PGO (profile-guided optimization)

**GCC:**

```bash
gcc -O2 -fprofile-generate prog.c -o prog_inst
./prog_inst &1 | grep -A20 '#include '
```

## Compiler-specific details

For GCC-specific flags, PGO nuances, and error patterns, see [gcc.md](reference/gcc.md).
For Clang diagnostics, optimization remarks, macOS toolchain, and clang-tidy, see [clang.md](reference/clang.md).
For C++20 modules, C++23/26, and C23 features, see [modern-cpp.md](reference/modern-cpp.md).

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [kaynetik](https://github.com/kaynetik)
- **Source:** [kaynetik/skills](https://github.com/kaynetik/skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-kaynetik-skills-c-cpp-compilers
- Seller: https://agentstack.voostack.com/s/kaynetik
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
