Skip to content

03. Why not format string?

cqwrteur edited this page Apr 28, 2024 · 4 revisions

Format strings were a historical mistake. Originally designed in the 1970s by AT&T Labs, they aimed to avoid adding excessive complexity to the C language and prevent language dependencies on I/O facilities. At that time, compilers needed to be simple, and computers were much slower. However, this rationale no longer holds true today. Format strings are now vulnerable to attacks, and there is no straightforward fix. Even restricting format strings to compile-time only does not fully address the issue (macros can still pose hazards and introduce localization challenges).

One could even argue that format strings remain problematic for localization, as they can be represented purely in binary form. Unfortunately, C++20’s std::format lacks several features that are mandatory for tools like GNU gettext, and finding an elegant solution without increasing complexity is challenging.

In this library, you will not encounter any format string; they are unnecessary.