c-cpp

Review C/C++ shim code and FFI boundaries for PostgreSQL extensions.

Updated Apr 15, 2026
One-click install
npx skills add https://github.com/preedep/kham --skill c-cpp-preedep
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: c-cpp
Source: https://github.com/preedep/kham/tree/main/.claude/skills/c-cpp
Command: npx skills add https://github.com/preedep/kham --skill c-cpp-preedep

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a focused approach to writing, reviewing, and debugging C and C++ code within the kham project, enabling reliable integration with the Rust core and PostgreSQL extension shims.

Core Features & Use Cases

  • Integrates Rust and C code through a trampoline/shim pattern, connecting PostgreSQL's fmgr with Rust logic.
  • Documents symbol exposure rules and best practices for building C shims (shim.c) alongside Rust crates via cc::Build.
  • Guides debugging of include orders, macro expansion, and FFI boundary issues to ensure correct cross-language calls.

Quick Start

Review the C/C++ code integration approach in kham to understand how the shim and trampolines coordinate Rust and C for PostgreSQL extensions.

Frequently Asked Questions about c-cpp

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure cc::Build in build.rs to compile a C shim for a Rust PostgreSQL extension?

To configure cc::Build for a PostgreSQL extension, you use build.rs to compile the C shim alongside your Rust crate, ensuring proper include orders and macro expansions are set for the FFI boundary.

What is the trampoline pattern for connecting Rust logic to a PostgreSQL C shim?

The trampoline pattern connects PostgreSQL's fmgr with Rust logic by using a C shim (shim.c) that acts as an intermediary, exposing Rust functions via extern C and no_mangle to the PostgreSQL extension interface.

Why are my Rust extern C functions not visible when calling them from a C file?

Rust extern C functions may not be visible from C if you do not use the no_mangle attribute, which prevents the compiler from renaming symbols and ensures correct FFI boundary exposure across languages.

How do I debug macro expansion and include order issues in a C and Rust FFI project?

Debugging macro expansion and include order in a C and Rust FFI project involves verifying the compilation sequence in build.rs and checking that C headers are correctly processed before Rust FFI bindings are generated.

Can I use this C/C++ integration approach for PostgreSQL extensions outside of the kham project?

This C/C++ integration approach focuses on the kham project's specific PostgreSQL extension bridge, but the documented trampoline pattern and cc::Build practices are applicable to similar Rust and C FFI integrations.

What are the limitations of using a C shim to bridge Rust and PostgreSQL's fmgr?

A limitation of using a C shim is the strict reliance on correct FFI boundaries and symbol exposure; any macro expansion or include order errors in the C file can break the Rust and PostgreSQL extension integration.