agentleFS
JuanMarchettoJuanMarchetto/agent-skills/skills/c-cpp-analyzer/SKILL.md

c-cpp-analyzer

Skill5 starsChanged 8 months agoMITView on GitHub

Analyze C/C++ code for Rust migration planning. Classifies functions by migration difficulty (easy/medium/hard), identifies unsafe patterns, pointer complexity, and macro usage. Use when: analyze C code, migration planning, C to Rust, assess migration difficulty, code complexity analysis.

The file

Files
SKILL.md

C/C++ Analysis for Migration

Difficulty Classification

Uses tree-sitter AST analysis with regex fallback:

  • Easy: Pure functions, simple arithmetic, no pointers, <30 lines
  • Medium: Pointer parameters, simple structs, bounded arrays, malloc with clear ownership
  • Hard: void*, function pointers, unions, goto, complex lifetimes, macro-heavy, coroutines

Hard signals (any 1 → Hard):

  • goto statements
  • union types
  • void* pointers
  • Function pointer callbacks
  • Coroutine patterns (Duff's device, switch-based state machines)
  • setjmp/longjmp

Medium signals (1+ with >30 lines → Medium):

  • Pointer declarations
  • Cast expressions
  • malloc/calloc usage

Pattern Detection

C PatternRust EquivalentDifficulty
ptr + len pairs&[T] slicesMedium
Error code returnsResult<T, E>Easy
NULL checksOption<T>Easy
malloc/freeVec<T>, Box<T>Medium
char* strings&str, StringMedium
Manual iteration with pointers.iter(), .enumerate()Medium
goto cleanupDrop trait, ? operatorHard
Global mutable stateFunction parameters, OnceLockHard
Bit manipulationSame ops with explicit typesMedium
unionenum with variantsHard
Function pointers / callbacksEnum dispatch (preferred) or Fn traitsHard
Linked lists (next/prev)Vec<T> (flatten)Medium
Type tag + union (tagged union)enum with data variantsMedium-Hard
Recursive data structuresenum + Box<T>Medium
Coroutine via switch/caseExplicit state machine (match loop)Hard
Printf format stringsformat!() / println!() macrosEasy-Medium
strdup/strcpy.to_string(), .clone()Easy

Size-Based Strategy

LOC RangeStrategyChunkingRepair Iters
<800Single-pass translationNoFull (5)
800-2000Chunked (400 LOC target)Structural (data model first)Full (8 for chunked)
2000+Chunked (500 LOC target)StructuralReduced (2)
4000+Consider per-module splitsplit_into_modules()Reduced (2)

Risk Flags

  • Platform-specific code (#ifdef _WIN32, inline assembly)
  • Undefined behavior (signed overflow, use-after-free patterns)
  • Macro-heavy code (requires cc -E expansion before analysis)
  • Variadic functions (... parameters)
  • setjmp/longjmp (no safe Rust equivalent)
  • Thread-unsafe global state
  • Bit-exact algorithms (compression, crypto) — very hard to get semantically correct
  • Files >4000 LOC — may exceed API token limits even with chunking

Migration Ceiling (learned from miniz)

Some patterns have NO safe Rust equivalent and require full algorithm redesign:

  • Coroutine via switch/case (Duff's device) → explicit state machine
  • Large structs with internal pointers (~300KB) → redesign needed
  • Bit-level DEFLATE/INFLATE → requires exact semantic preservation
  • These files need "best-effort" mode: output highest-quality version for developer to finish

Powered by Noricum — autonomous C/C++ to Rust migration agent

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.