migoEX
asked on
Pure C - function with optional arguments only
Hi,
I want to declare a function, which has no required parameters, but may have optional, and do it in pure C.
It's simple for functions having at least one parameter:
void my_func( char *sFirst, ... );
and then accessing the optional using arg_list.
I want to define something like
void my_func( ... );
but it's not valid :(
I'll appreciate your help.
I want to declare a function, which has no required parameters, but may have optional, and do it in pure C.
It's simple for functions having at least one parameter:
void my_func( char *sFirst, ... );
and then accessing the optional using arg_list.
I want to define something like
void my_func( ... );
but it's not valid :(
I'll appreciate your help.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
There is 1 problem left:
I want this function to be exported, and used by "external" functions. If in my H file I declare the function without parameters, the caller won't be able to compile a code, which is passing parameter. And vise versa - if I define it with parameter, a call without passing parameters won't compile.
PS: I'm not sure it's possible :) but may be I'm missing some solution
I want this function to be exported, and used by "external" functions. If in my H file I declare the function without parameters, the caller won't be able to compile a code, which is passing parameter. And vise versa - if I define it with parameter, a call without passing parameters won't compile.
PS: I'm not sure it's possible :) but may be I'm missing some solution
Even I would be interested in the solution if this was possible ...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, mtmike!
That's exactly what I was looking for :)
That's exactly what I was looking for :)
something like
while ((ch = getopt(argc, argv, "a:dhf:l:m:np:rs:v")) != EOF)
should serve your purpose
the above line of code is from syslogd source code