by layer8 · 3y ago · 0 comments
Also, in personal projects, I almost always used custom wrapper functions for printf/fprintf/sprintf for various reasons, so that default wouldn’t be of much use, unless maybe I could enable it for the custom functions.
For loading translated strings, I'm missing some library function to verify whether two format strings are argument-compatible.
(I have no recommendations. When I've seen this stuff done properly, on the occasions I've managed not to avoid doing it, it's always been using some in-house system.)
You can with the $ syntax. Never seen it used though. Maybe it isn't very portable.
I think the real reason you rarely see it, is it is only used with internationalisation–the idea being if you translate the format string, the translator may need to reorder the parameters for a natural translation, given differences in word order in different languages. However, a lot of software isn't internationalised, or if it is, the internationalisation is in end-user facing text, which nowadays usually ends up in a GUI or web UI, so printf has less to do with it. And the kind of lower-level tools/components for which people still often use C are less likely to be internationalised, since they are targeted at a technical audience who are expected to be able to read some level of English.
I like printf format strings, but as a way of handling localizable strings I don't think they are the best.
Aren't those usually resolved to string literals by preprocessor such that the compiler still could emit a warning?