Re: Function with unspecified number of arguments
- From: somenath <somenathpal@xxxxxxxxx>
- Date: Thu, 31 Jan 2008 02:33:36 -0800 (PST)
On Jan 31, 9:21 am, Jack Klein <jackkl...@xxxxxxxxxxx> wrote:
On Wed, 30 Jan 2008 06:34:18 -0800 (PST), somenath
<somenath...@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.
Thanks for the replies . But I am confused by your statement
"accepting an unspecified, but fixed,
argument list."
Are you indicating type of the arguments are unspecified but the
number of argument is specified If it is is fixed is it none ?
.
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.
- Follow-Ups:
- Re: Function with unspecified number of arguments
- From: Ben Bacarisse
- Re: Function with unspecified number of arguments
- References:
- Function with unspecified number of arguments
- From: somenath
- Re: Function with unspecified number of arguments
- From: Jack Klein
- Function with unspecified number of arguments
- Prev by Date: Re: My solution to allocating memory
- Next by Date: Quick check on signed promotion of bytes
- Previous by thread: Re: Function with unspecified number of arguments
- Next by thread: Re: Function with unspecified number of arguments
- Index(es):
Relevant Pages
|