Re: Function with unspecified number of arguments
- From: Jack Klein <jackklein@xxxxxxxxxxx>
- Date: Wed, 30 Jan 2008 22:21:27 -0600
On Wed, 30 Jan 2008 06:34:18 -0800 (PST), somenath
<somenathpal@xxxxxxxxx> wrote in comp.lang.c:
Hi All,
I have one question regarding unspecified number of argument of
function.
I would like to know why functions are allowed to define with
unspecified number of arguments ?
C does not allow the definition of functions with unspecified numbers
of arguments.
For example
void f()
{
}
The function body above defines a function that accepts NO ARGUMENTS
and returns nothing.
If you had not included the body, just this:
void f();
....then you would have provided a declaration, not a prototype, of a
function returning nothing and accepting an unspecified, but fixed,
argument list.
But you did not, and cannot in C, define such a function.
int main(void)
{
f(3,4);
f(3,4,3);
return 0;
}
Inside void f() what ever argument is passed from main is useless . So
where function with unspecified number of arguments are useful ?
As has been said, calling f() with any arguments at all produces
undefined behavior.
All you did was tell the compiler not to check that you called f()
correctly, that you would be responsible for doing so.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
.
- Follow-Ups:
- Re: Function with unspecified number of arguments
- From: somenath
- Re: Function with unspecified number of arguments
- References:
- Function with unspecified number of arguments
- From: somenath
- Function with unspecified number of arguments
- Prev by Date: Re: Strange C operator
- Next by Date: Re: Strange C operator
- Previous by thread: Re: Function with unspecified number of arguments
- Next by thread: Re: Function with unspecified number of arguments
- Index(es):
Relevant Pages
|