The reason the 1 is not converted to 1.0 is that printf
is “just” a C function with a variable number of arguments, and only the first (required) argument has a specified type (const char *
). Therefore the compiler “cannot” know that it should be converting the “extra” argument—it gets passed before printf
actually reads the format string and determines that it should get a floating point number.
Now, admittedly your format string is a compile-time constant and therefore the compiler could make a special case out of printf
and warn you about incorrect arguments (and, as others have mentioned, some compilers do this, at least if you ask them to). But in the general case it cannot know the specific formats used by arbitrary vararg functions, and it's also possible to construct the format string in complex ways (e.g. at runtime).
To conclude, if you wish to pass a specific type as a “variable” argument, you need to cast it.