Quote:
Therefore, the correct parameter types must be always passed to variadic argument functions.

But that was exactly my point!

va_arg(foo, float) is undefined behaviour, because float is automatically promoted to double when passed to a variable argument, because the compiler can't deduce the right type and default argument promotion kicks in. Here is the relevant quote from the C standard (emphasis mine):
Quote:

6) If the expression that denotes the called function has a type that does not include a prototype, the integer promotions are performed on each argument, and arguments that have type float are promoted to double. These are called the default argument promotions. If the number of arguments does not equal the number of parameters, the behavior is undefined. If the function is defined with a type that includes a prototype, and either the prototype ends with an ellipsis (, ...) or the types of the arguments after promotion are not compatible with the types of the parameters, the behavior is undefined. If the function is defined with a type that does not include a prototype, and the types of the arguments after promotion are not compatible with those of the parameters after promotion, the behavior is undefined, except for the following cases: [...]

(ISO C99, latest draft, §6.5.2.2)

Yes, it's a stupid rule that is dragged along because K&R C didn't have support for function prototypes. With all that said, it breaks support for external languages badly. Sure, you may now argue that variadic functions are rarely used, to which I'm going to argue that they are used quite extensively when it comes to scripting languages. Can this at least be mentioned in the manual? Because other languages will expect default type promotion because not expecting is results in undefined behaviour.


Edit:
Originally Posted By: jcl
It won't. A real programmer does not write pc_1[i][j], but pc_1[j+121*i]. Multidimensional arrays are for pussies. wink

I would like to confirm that! I have used multidimensional arrays in various circumstances before and I'm the biggest pussy on earth. I also very much like compiler boundary checks and faster insertion/deletions of whole rows when working with dynamically allocated ones.

Last edited by JustSid; 11/25/13 15:34.

Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com