Link to home
Start Free TrialLog in
Avatar of migoEX
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.
Avatar of sunnycoder
sunnycoder
Flag of India image

man 3 getopt

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
SOLUTION
Avatar of Ajar
Ajar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of migoEX
migoEX

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
Even I would be interested in the solution if this was possible ...
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of migoEX

ASKER

Thanks, mtmike!

That's exactly what I was looking for :)