Paul Krill
Editor at Large

TrapC proposal to fix C/C++ memory safety

news
Feb 28, 20252 mins
Application SecurityC++Programming Languages

The C-language extension compiler includes memory-safe pointers along with new safety features not found in C or C++.

Credit: iStock/pideluxe

TrapC, a fork of the C language, is being developed as a potential solution for memory safety issues that have hindered the C and C++ languages.

TrapC is a proposed C-language extension compiler intended to be implemented as a cybersecurity compiler for C and C++ code, said developer Robin Rowe. โ€œThink of TrapC as wishing C was memory-safe, while also wishing it a bit more like C++, but not so much that it becomes a lot to learn like C++. C code can be safer with C++ constructors and destructors,โ€ said Rowe. โ€œMoreover, C/C++ code should be safe by default, not blunder on after a programmer didnโ€™t check for an error code.โ€

Due by the end of this year, TrapC will be a free, open source compiler similar to Clang and C++, Rowe said. TrapC has pointers that are memory-safe, addressing the memory safety issue with the two languages. With TrapC, developers write in C or C++ and compile in TrapC, for memory safety.

TrapC is an extension of the C programming language that removes the keywords goto and union, adds the keywords trap and alias, and adopts a few features from C++ that improve safety such as constructors and destructors, said Rowe. It also provides a couple of new features not in C or C++. Despite being a minimalist programming language with the same number of keywords as C, TrapC has a surprising amount of C++ code compatibility, he said.

Rowe presented TrapC at an ISO C meeting this week. Developers can download a TrapC whitepaper and offer Rowe feedback. According to the whitepaper, TrapCโ€™s memory management is automatic and cannot leak memory. Pointers are lifetime-managed, not garbage-collected. Also, TrapC reuses a few code safety features from C++, notably member functions, constructors, destructors, and the new keyword.

TrapC is not the only attempt to deal with memory safety in C or C++. The C++ Partnership worked on its Safe C++ Extensions project to remedy C++memory ย safety. Rowe said that other proposals do not offer the comprehensive memory safety offered by TrapC.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorldโ€™s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorldโ€™s audience of software developers and other information technology professionals. Paul has won a โ€œBest Technology News Coverageโ€ award from IDG.

More from this author