[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: what is a wrapper function?



A wrapper function is a function whose primary purpose is to call
another function.  A simple (and useless) wrapper function would be:

int A (int x, int y, int z)
{
    return B(x,y,z);
}

One use for wrapper functions is that you can modify the arguments:

int add_three_nums (int x, int y, int z)
{
    return add_two_nums(x+y, z);
}

Or you can modify the return value:

char *allocate_memory (int size)
{
    char *mem = my_alloc(size);
    if (!mem)
        return ERR_PTR(-ENOMEM);
    else
        return mem;
}

You can also use it if:
- you want to only export the wrapper functions but not the internal
ones.  
- you want to do something simple before and/or after the function call
(such as checking arguments)

I probably also missed several uses for them, but I hope you get the
idea.

Avishay

On Mon, 2006-01-02 at 20:15 +0530, Md.Zaheeruddin Khan wrote:
> HI ,
> I want 2 know what is a wrapper function and where is it used?
> Thanks in anticipation,
> Zaheer


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/