Path: utzoo!attcan!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: 'void' arguments (Yet Another Feature Proposal) Message-ID: <565@taumet.com> Date: 23 Jan 91 16:15:48 GMT References: <943@tuura.UUCP> Distribution: comp Organization: Taumetric Corporation, San Diego Lines: 45 risto@tuura.UUCP (Risto Lankinen) writes: >Suppose there's function... > SetThisMode( int iMode,int iValue1,int iValue2,int iValue3 ); >also suppose the documentation says that 'when iMode==, then none of >the iValue:s have any effect'. In code you'd then write: > SetThisMode( ,0,0,0 ); or SetThisMode( ,, > , ); >when you could be doing... > SetThisMode( ,(int)any,(int)any,(int)any ); >where the 'any' is my proposal for a keyword (as promised in the header). >It could be any other, too, for that matter - I actually tried some 'void' >derivatives, to check out whether there already were a legal way to do so. This problem is already solved in two different ways in C++. 1. Default parameters. You may specify default values for any (or all) trailing parameters in the prototype. Any of the rightmost parameters with default values may be omitted in a call: SetThisMode( int iMode, int iValue1=0, int iValue2=0, int iValue3=0); can be called as any of SetThisMode(fee>); SetThisMode(fie>, 1); SetThisMode(foh>, 1, 2); SetThisMode(fum>, 1, 2, 3); This does not address your efficiency concern. 2. Overloaded functions. You may define more than one function with the same name, as long as their calling sequences are different: SetThisMode( int iMode); SetThisMode( int iMode, int iValue1); SetThisMode( int iMode, int iValue1, int iValue2); SetThisMode( int iMode, int iValue1, int iValue2, int iValue3); The compiler calls version of the function with the matching calling sequence. Since only the supplied parameters are passed, you get the most efficient possible call. -- Steve Clamage, TauMetric Corp, steve@taumet.com