On Sep 2, 6:46 am, karthikbalaguru <karthikbalagur...@gmail.com>
wrote:
Is it possible to define default values for arguments that are not
passed when the function call is made ?
I tried it , but it showed linking errors. Any other ideas/help ?
Unless the function is variadic and has a declaration of the form
T f(T, ...); or the ill-advised and old fashioned form
T f(); you must pass all arguments.
A common idiom is to pass flags in the required arguments
which indicate which of the optional arguments are being
passed (eg open() in unix). For example, if you have a
function that constructs an empty list that takes 2
optional arguments, an initial size and a memory allocation
function, you could do:
struct list * new_list( int flags, ...);
and make calls to it like:
struct list * A;
A = new_list( 0 );
A = new_list( LIST_SIZE, 1024 );
A = new_list( LIST_SIZE | LIST_MALLOC, 1024, malloc );
In the definition of new_list(), you check the flags
and set values appropriately.