Bearing in mind the answers given to a question about a safer formatting library for C, I’m wondering whether there is a safe C formatting library?
What I mean is:
- there’s no possibility to mismatch the format string from the arguments
- there’s no possibility to crash by passing the wrong type
- there’re no platform-dependent aspects
Please don’t answer about the Microsoft Safe String Library, or libraries that are less unsafe but still not totally safe, as I’m aware of these, and they don’t satisfy the requirements for total safety.
Thanks in advance
You’re writing in C. C is not type-safe. You cannot avoid undefined behaviour if you pass an
int*instead of achar*. There’s no such thing as “there’s no possibility” if your variables are not statically type checked / tagged for runtime checking.If you have something that produces warnings, that’s quite good already…
If you really need or want safety, you may want to have a look at cyclone (C dialect), or some completely different languages.