3 ms·
What I wonder is, why didn't they add new *printf functions? So you could say 'printf("int64: %d64", x)'
by earenndil 7y ago
What I wonder is, why didn't they add new *printf functions? So you could say 'printf("int64: %d64", x)'
- boomlinde 7y agoBackward compatibility. Your example would impose additional constraints on the %d specifier that would likely break existing code. What if you want an int immediately followed by literal ”64”?
- earenndil 7y agoOops, I typoed. I said 'new *printf functions'; the example was supposed to be 'printf2("int64: %d64", x)'
- boomlinde 7y agoI see! That would make more sense, but I still think the inttypes.h macros are a sufficient solution. Implementers and standards influencing users probably aren't too keen on another formatting language when you can implement it as macros that only take another few characters to use. printf2("int64: %d64", x); for example isn't significantly shorter than printf("int64: %" PRId64, x); Perhaps it's easier to read, but when you have to support both, and you're more likely to run into the latter than the former anyway, I think it just adds cognitive overhead to have to consider which formatting language is being used.