Imagine you have this function:
void foo(long l) { /* do something with l */}
Now you call it like so at the call site:
foo(65); // here 65 is of type int
Why, (technically) when you specify in the declaration of your function that you are expecting a long
and you pass just a number without the L
suffix, is it being treated as an int
?
Now, I know it is because the C++ Standard says so, however, what is the technical reason that this 65
isn't just promoted to being of type long
and so save us the silly error of forgetting L
suffix to make it a long explicitly?
I have found this in the C++ Standard:
4.7 Integral conversions [conv.integral]
5 The conversions allowed as integral promotions are excluded from the set of integral conversions.
That a narrowing conversion isn't being done implicitly, I can think with, but here the destination type is obviously wider than the source type.
EDIT
This question is based on a question I saw earlier, which had funny behavior when you didn't specify the L
suffix. Example, but perhaps it's a C thing, more than C++?!!