New approach combines formal rules and LLMs to translate C macros better
Researchers prove combining formal methods with LLMs beats either alone in macro translation
Researchers from the University of Central Florida have developed a novel approach to translating C macros—named fragments of code that C lacks but which permeate real-world software—into safer languages like Rust. In a paper submitted to ASE 2026, the team introduced MerC, the first formally-specified translator for C macros, and MacroBench, the first benchmark designed to test macro translation capabilities.
The study found that traditional preprocessing-based methods fail to preserve macro semantics, resulting in translations that diverge significantly from the original C code. While large language models (LLMs) alone can translate 22% to 77% more of MacroBench test cases than MerC, they do so with error rates ranging from 8% to 28%, necessitating developer validation. The breakthrough comes from combining MerC and LLMs in a 'tag team' approach: preprocessing macros with MerC first, then using LLMs for the remaining cases. This method reduced the average failure rate by 32% and increased the average number of test cases translated by 51% compared to using either technique alone, all while maintaining MerC’s 100% accuracy rate on supported cases.
- MerC, the first formally-specified C macro translator, supports 50% of MacroBench test cases with zero errors
- LLMs alone translate 22-77% more cases but with 8-28% error rates requiring manual review
- Combining MerC with LLMs reduces failure rates by 32% and increases coverage by 51% over standalone methods
Why It Matters
This hybrid approach could dramatically improve the safety of critical C-based systems by enabling accurate migration to memory-safe languages like Rust.