Q
Quentin Pope
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?
QP
***
This email and any file attachments(s) are confidential, may be legally
privileged, and are intended solely for use by the identified recipient
(s). If you received the email in error, please notify the sender and
delete the message and any copies completely from your computer.
Dissemination, distribution, or copying of this communication, in whole
or in part, by any unintended or unauthorized recipient is prohibited and
may subject you to liability under 18 U.S.C. sec. 2511. Jameston
Solutions, Inc. assumes no liability and makes no warranties or
representations that the email or any file attachments are totally secure
and/or virus free. The recipient is advised to check for viruses prior to
opening any file attached to the email. Statements contained in the email
or any file attachment may not be authorized or endorsed by Jameston
Solutions, Inc. Jameston Solutions, Inc. accepts no liability, whether in
contract, tort, or equity, for any unauthorized statement or offer of
contract communicated in the email or any file attached by the sender. No
employee or agent is authorized to conclude any binding agreement on
behalf of Jameston Solutions, Inc with another party by email without
express written confirmation
WARNING: Computer viruses can be transmitted via email. The recipient
should check this email and any attachments for the presence of viruses.
The company accepts no liability for any damage caused by any virus
transmitted by this email. E-mail transmission cannot be guaranteed to be
secure or error-free as information could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or contain viruses. The
sender therefore does not accept liability for any errors or omissions in
the contents of this message, which arise as a result of e-mail
transmission.
Warning: Although the company has taken reasonable precautions to ensure
no viruses are present in this email, the company cannot accept
responsibility for any loss or damage arising from the use of this email
or attachments.
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?
QP
***
This email and any file attachments(s) are confidential, may be legally
privileged, and are intended solely for use by the identified recipient
(s). If you received the email in error, please notify the sender and
delete the message and any copies completely from your computer.
Dissemination, distribution, or copying of this communication, in whole
or in part, by any unintended or unauthorized recipient is prohibited and
may subject you to liability under 18 U.S.C. sec. 2511. Jameston
Solutions, Inc. assumes no liability and makes no warranties or
representations that the email or any file attachments are totally secure
and/or virus free. The recipient is advised to check for viruses prior to
opening any file attached to the email. Statements contained in the email
or any file attachment may not be authorized or endorsed by Jameston
Solutions, Inc. Jameston Solutions, Inc. accepts no liability, whether in
contract, tort, or equity, for any unauthorized statement or offer of
contract communicated in the email or any file attached by the sender. No
employee or agent is authorized to conclude any binding agreement on
behalf of Jameston Solutions, Inc with another party by email without
express written confirmation
WARNING: Computer viruses can be transmitted via email. The recipient
should check this email and any attachments for the presence of viruses.
The company accepts no liability for any damage caused by any virus
transmitted by this email. E-mail transmission cannot be guaranteed to be
secure or error-free as information could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or contain viruses. The
sender therefore does not accept liability for any errors or omissions in
the contents of this message, which arise as a result of e-mail
transmission.
Warning: Although the company has taken reasonable precautions to ensure
no viruses are present in this email, the company cannot accept
responsibility for any loss or damage arising from the use of this email
or attachments.