This may be a silly question, but could someone please provide a standard reference for C++11 and C11:
Is char default-promoted to int?
Here’s a little background: Both C and C++ have notions of default argument promotion (C++11: 5.2.2/7; C11: 6.5.2.2/6). This entails that in the following call, the arguments are promoted:
void f(int, ...);
float a = 1; short int b = 2; char c = 'x';
f(0, a, b, c);
For the function call, a is converted to double and b is converted to int. But what happens to c? I have always been under the impression that char also gets promoted to int, but I cannot find the relevant statement in the standards.
C++
In C++ 2011 (ISO/IEC 14882:2011), the relevant parts seem to be:
I’ve separated the last two sentences to give them emphasis. They’re a continuous part of paragraph 7 in the standard.
Etc.
C
C has two contexts where arguments are default promoted. One is when there is no prototype in scope for a function (first covered by another answer), and the second when there is a prototype with ellipsis. C++ does not allow the first case at all, of course. These quotes are from the same sections of the standard as chosen by another answer, but the snippets here are somewhat longer. They were found by independent analysis of the standard, and it was only when cross-checking that I noticed that the sections are the same.
In C 2011 (ISO/IEC 9899:2011), the relevant parts seem to be:
The ‘integer promotions’ are defined in §6.3.1.1:
I note that at one time, the question listed the function
void f(...);, which is a C++ function and not a C function; C does not allow the ellipsis to appear as the only argument to the function. The question has since been updated tovoid f(int, ...);which is valid in both C and C++.