> Recently, a coworker of mine told me how she thought the compiler should catch when you don't give printf the right arguments.
The fact that you think she's wrong, and that you're right, on this issue, suggests you don't understand how compilers work either. 99% of printf fails are catchable through static analysis, and should be caught that way.
But is the static analysis of input strings passed to a random library function really a core feature of a compiler, just because the compiler has a switch for such analysis? Yes, it's a feature of modern well-engineered tool, but I would argue it's strictly not part of the compiler.
> The fact that you think she's wrong, and that you're right, on this issue, suggests you don't understand how compilers work either.
I'm happy to be proven wrong and certainly know I have much more to learn but I suspect in this case I was not clear in my comment and consequently you made assumptions about what I think is right or not. Feel free to correct me =] Either way I appreciate the response
> 99% of printf fails are catchable through static analysis, and should be caught that way.
I never said that it wasn't possible! But that would require the compiler have special logic just for printf or in this case the fmt and log packages. Maybe you would think that's the right thing to do, and I can see that point of view, but I suspect you would at least understand why it is a controversial decision and thus not necessarily assume it's there.
GCC does catch problems with printf arguments vs the format string and it has mechanisms for defining functions that take the same format strings. I operate at a high enough warning level that I see this type of warning now and then.
Ah interesting to know that GCC does this! I figured there would be compilers which did this but I sadly didn't have any examples.
> the compiler DOES have that special logic.
Indeed it being a controversial decision does not imply that no compilers would do it; if anything it implies that there should be some compilers which make that choice.
In a totally pendantically isolated world that's true. It's not an actual hindrance to implementing something like this, as long as it can be turned off for people not using the usual stdlib.
The other issue with printf and every other templating mechanism is that the format string or template itself might be computed rather than being a static literal. Also, the types of the formatted arguments may not be decided statically.
The fact that you think she's wrong, and that you're right, on this issue, suggests you don't understand how compilers work either. 99% of printf fails are catchable through static analysis, and should be caught that way.