c - How to allow variable parameters passed to function -
i have function accepts 3 parameters, want accept first 2 , not care third. how can in c. tried declaring function in header file void list()
thinking might imply don't care how many parameters didn't work.
void list(uint8_t _pin, unsigned int time, unsigned long tasks)
what want called variadic function. can accept variable number of arguments.
**famous examples: printf()
/scanf()
these functions contain ellipsis (…
) notation in argument list, , uses special macros access variable arguments.
the basic idea write function accepts variable number of arguments. so, must declared prototype says so.
the syntax of iso c requires @ least 1 fixed argument before …
. thus, write fixed arguments usual, , add …
notain @ end of parameter list indicate possibility of additional arguments. example,
int func (const char *a, int b, …) { … }
defines function func()
returns int
, takes 2 required arguments, const char *
, int
. these followed number of anonymous arguments.
you can check on-line gnu manual more details.
Comments
Post a Comment