How to use Claude to port C code to C++
The author reports that Claude resolved output differences between the C and C++ versions, including restoring original behavior where apparent fixes broke byte equivalence.
Prompt to try
Editorial adaptation, not the source author’s exact prompt. Replace bracketed inputs and review tool permissions first.
Port [legacy C application] to structured C++ while preserving byte-for-byte output. Build comparison tests against [original executable] using [input fixtures]. Investigate discrepancies with hex dumps and small diagnostic programs, and report any original bugs that must be preserved.
Reach people exploring AI agents
See placements →What happened
The author reports that Claude resolved output differences between the C and C++ versions, including restoring original behavior where apparent fixes broke byte equivalence.
Reported by wvenable on Hacker NewsHow the agent did it
- Convert the intertwined C application into structured C++.
- Design tests comparing old and new application outputs.
- Investigate differences with hex dumps and Python programs.
Where a person stepped in
The author set byte-for-byte compatibility as the goal; the post does not describe final line-by-line review.
A person approved each step before the agent continued.
The author had shelved a complex C application because its intertwined logic made it difficult to understand. They later used Claude in agent mode to port that application into more structured C++. Although the initial conversion was useful, the agent still struggled with parts of the original logic.
To keep the port faithful, the author had Claude design a test suite comparing outputs from the old and new applications. When results differed and the cause was unclear, Claude generated hex dump comparisons, wrote small Python programs, and analyzed the evidence. It repeatedly built the code, ran the tests, compared outputs, and revised the implementation until the differences were resolved.
The target was byte-for-byte equivalence rather than simply improving behavior. The author says some discrepancies were likely bugs in the original application that Claude had fixed during conversion. To preserve compatibility, those behaviors had to be reintroduced into the new implementation. The account reports successful resolution of the observed differences, but does not quantify the test suite or claim that every possible input was covered.
Who it's for: Developers porting legacy programs where preserving existing output matters more than correcting historical behavior during the migration.
Prompt
Suggested prompt (written by Agents In Use, not the author's)
Source: Hacker News · wvenable
Frequently asked questions
How did the author check the port?
They had Claude create a test suite comparing output from the old C application with output from the new C++ application.
Why were apparent bugs reintroduced?
The author wanted byte-for-byte output equivalence, so behavior thought to be buggy in the original had to be preserved when correcting it produced differences.
More details
Remaining steps
- Build, test and revise until observed differences are resolved.
- Reintroduce original behavior where needed for byte equivalence.
About this account
Claude built code, ran comparison tests and investigated discrepancies with additional diagnostic programs before revising the port.
Platform: Hacker News. Attribution: https://news.ycombinator.com/item?id=46227900. Prompt: Suggested (written by Agents In Use, not the author's). Sourced by the Agents In Use pipeline.
Credit: wvenable on Hacker News
Source published 11 Dec 2025
Source checked 14 Oct 2026
Tools and topics
Claude · C · C++ · Python · Hex dumps
C++ · Legacy migration · Compatibility
Editorial completeness: 100/100. Measures documented fields, not agent performance or verified outcomes.