Hacker News new | past | comments | ask | show | jobs | submit login

Because printf is just a function, and doesn't have access to the type information at the call-site.



Just a hypothetical idea: what if the standard allowed a compiler to modify the format string during compilation, replacing e.g. %N with the appropriate conversion specification, subject to proving that a given format string is a plain old literal that is not touched anywhere else?


Although compilers will warn about it, it's still possible to generate a format string dynamically at runtime. This might be done if you want different formats for the same fixed argument types (though there are probably better/safer ways).


This is exactly what I was suggesting. The compiler definitely has that information.


It's a good idea, but then you are tied to one compiler.

So, what if Clang implements it, but not GCC? Or what if Clang and GCC implement it, but not the Sun or Intel compilers? Or what about all the GCC copies every board maker forks when they create something custom?

It's tricky making in-compiler behavior non-standard (though, I guess that's what compiler flags are for).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: