Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C Question, 1

Status
Not open for further replies.

philk12

Programmer
Dec 29, 2005
20
US
Sorry if this is not the C forum, but couldn't find C only C++.

I have procedures where the first two parameters are alternates, i.e.values must be supplied for
param1, param3, param4, etc
or
param2, param3, param4, etc

However I need to call some of these routines from some legacy C code.


How do I specify in C (both the prototype and the code) that param1 & param2 can be *OMIT'd?


 
Neither C nor C++ allows optional parameters to be specified before required ones. In C++, optional parameters can only be specified at the end like this:
Code:
void func( int param1, int param2, int optional1 = 0, int optional2 = 0 )
{
   ...
}
I'm not familiar with the latest C standard, but I don't believe you can overload a function like that in any version of C.

However, if you are really getting desperate, you could always use the ... operator the way functions like printf() & scanf() do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top