Re: Function with unspecified number of arguments



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.

.



Relevant Pages

  • Re: Function with unspecified number of arguments
    ... void f ... The function body above defines a function that accepts NO ARGUMENTS ... undefined behavior. ... All you did was tell the compiler not to check that you called f ...
    (comp.lang.c)
  • Re: Should function argument be changed in function body?
    ... function body. ... void foo1 ... value will not affect caller code and it saves stack size. ... Translating the C code into assembler may well lead to loading an often used argument into a register, retrieving it only from this register, nothing forces the compiler to "leave" the variable in the stack. ...
    (comp.lang.c)
  • Re: A description of function parameters
    ... > void foo; ... "9 Each parameter has automatic storage duration. ... redeclared in the function body except in an enclosed block). ... "10 On entry to the function, the size expressions of each variably ...
    (comp.lang.c)
  • Re: Should function argument be changed in function body?
    ... > I was taught that argument valuse is not supposed to be changed in ... > function body. ... > void foo1 ... > value will not affect caller code and it saves stack size. ...
    (comp.lang.c)
  • [2.4 patch][1/6] lmc_media.c: fix gcc 3.4 compilation
    ... 'lmc_trace': function body not available ... void lmcConsoleLog(char *type, unsigned char *ucData, int iLen); ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)