|
|
|
|
|
by jzwinck
4272 days ago
|
|
Glibc may have register_printf_function, but GCC does not have register_printf_attribute, so this is not as practical as it could be. That is: __attribute__ ((format (printf, 1, 2)))
attaches to a function declaration to indicate that the function works like printf, so GCC can warn if a (compile time) format string does not match the variadic arguments. But there seems to be no way to extend this attribute, nor to make entirely new attributes in the same spirit.So you can register new format specifiers for printf, but it seems you'll then have to disable warnings about bad format specifiers during compilation. Those warnings have very few false positives and catch real bugs in real code. |
|
Yes, GCC knows, and we're good with that :)
The glibc extension here serves no earthly purpose (and on the gcc side, we've considered pretending it doesn't exist before so we can actually optimize better).
It sounds like it may be a good idea, except 1. It modifies functions that have a standard purpose, standard set of format specifiers, and are, as you point out, often error checked to make sure they match those :)
2. Unless you see the printf handler registration, which may be in a library, linked to your program, or whatever, you'll have no idea that the code is wrong.