Should all printf parameters be specified to make sure they are of the expected type?
Not at all. You must use the correct combination of format specifier and argument type for each argument you pass. Of course, if you have an argument that is the "wrong type" (for example, the int you want to print using the floating point format specifier), you need to convert it somehow, which usually means throwing. But dispersing the load of drops on all your printf lines “just in case” is not the right solution here.
Please note that the compiler does not require "understanding" the printf format printf (either scanf or strftime , etc.), therefore the compiler is simply obliged to pass arguments in accordance with the specified list of restrictions ( float converted to double , short integers ( char , short ) are converted to int and some other similar things). Then, before printf you can determine what you have. And, of course, if you do not have the correct format specification for the argument, then printf may indeed be in the wrong place for the arguments.
So, in general, you need to match the argument type for printf . If that means you sometimes need a throw, then yes, use a throw. But this should not be a "normal thing."
source share