C
CryptiqueGuy
Consider the variadic function with the following prototype:
int foo(int num,...);
Here 'num' specifies the number of arguments, and assume that all the
arguments that should be passed to this function are of type int.
(My question has nothing to do with the definition of the function
foo, so don't bother about it.)
If I call the function as:
foo(2,3,4,5,6,7,8);/*More arguments than expected*/
Here I call foo with too many arguments than expected by its
definition.
Assuming that the prototype is visible in the scope of the function
call and the definition of function foo itself does NOT produce any
UB, please tell me if this function call produces UB or not.
I am not able to find any explicit clause from C99 which deals with
this behavior.
Though I find that:
7.19.6.1 The fprintf function
The fprintf function writes output to the stream pointed to by stream,
under control of the string pointed to by format that specifies how
subsequent arguments are converted for output. If there are
insufficient arguments for the format, the behavior is undefined. If
the format is exhausted while arguments remain, the excess arguments
are evaluated (as always) but are otherwise ignored.
This is highly specific to fprintf. I wonder if it applies to all
variadic functions.
Can I assume that the behavior of this function call is UB by
ommission?
Or am I missing something, here?
Please clarify
Thanks in advance for reply.
int foo(int num,...);
Here 'num' specifies the number of arguments, and assume that all the
arguments that should be passed to this function are of type int.
(My question has nothing to do with the definition of the function
foo, so don't bother about it.)
If I call the function as:
foo(2,3,4,5,6,7,8);/*More arguments than expected*/
Here I call foo with too many arguments than expected by its
definition.
Assuming that the prototype is visible in the scope of the function
call and the definition of function foo itself does NOT produce any
UB, please tell me if this function call produces UB or not.
I am not able to find any explicit clause from C99 which deals with
this behavior.
Though I find that:
7.19.6.1 The fprintf function
The fprintf function writes output to the stream pointed to by stream,
under control of the string pointed to by format that specifies how
subsequent arguments are converted for output. If there are
insufficient arguments for the format, the behavior is undefined. If
the format is exhausted while arguments remain, the excess arguments
are evaluated (as always) but are otherwise ignored.
This is highly specific to fprintf. I wonder if it applies to all
variadic functions.
Can I assume that the behavior of this function call is UB by
ommission?
Or am I missing something, here?
Please clarify
Thanks in advance for reply.