I’ve done a bit of PHP and when you declare variables you do not need to declare the type (eg. string or int).
However I have to tweak a very simple C file and, in order to get the print function to work correctly, I have to include a type specifier for the output of each variable.
Why isn’t this type automatically inferred from the variable itself?
Because
printfis part of the C-compatibility part of C++, where type detection wasn’t so hot 🙂There is a disconnect between the specifiers in the format string and the data items being used for that specifier, for example:
If you use C++ streams for your output, this isn’t so much of an issue.