Paul, Let me rephrase the question is it possible to form the va_list type of variable programmatically and send it to a function. Else.
Was interested in knowing how variable arguments can be decided on the fly and calls made to a function capable of accepting variable arguments. Generally we find hard coded calls which pass 1,2,3 ...n of arguments to a function capable of handling multiple arguments. How should the implementation of the function be for which the number of parameters (dynamic ) that need to be passed to this function be which is decided at runtime based on program logic. How should a multiple arguments function make calls to a function accepting multiple args . The calling function needs to decide the multiple calling args at runtime and make a call to multiple arg function. Probably this is a asking for a utopian solution . Is it asking for too much as always the parameters that need to be passed to a multiple arg function are always known before hand and this situation does not normally arise. Regards, Kiran ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Paul Herring Sent: Monday, February 18, 2008 3:40 PM To: [email protected] Subject: Re: [c-prog] variable arguments On Feb 18, 2008 9:09 AM, Kiran Divakaran <[EMAIL PROTECTED]<mailto:kiran_divakaran%40infosys.com>> wrote: > > Hi All, > > Please let me know how variable argument functions can be dynamically churned > and the va_start , va_arg , va_end functions be used for the same. > > Generally the va_ functions are used when the variable list of arguments are > expected to a function like say > > int test_routine(char *s, const char *format, ...) One of the defined arguments ('s' and 'format' in your example) should indicate the number of, and type, of the variable arguments supplied. printf(), for example has the % placeholders in the 'format' string to perform this function. > now I could have calls like the below and all of them would be handled by the > above definition . > > All the below calls are hard coded and calls are made . > > > test_routine("Hello" , "Test", 1 , 100 , "Mark"); > test_routine("Hello" , "Test", 1 "Twain"); > test_routine("Hello" , "Test", 1 , 100 ); Here you don't appear to give any indication of what the variable arguments are - and it's impossible to (generically) query the va_ system to find them out. -- PJH http://shabbleland.myminicity.com **************** CAUTION - Disclaimer ***************** This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the use of the addressee(s). If you are not the intended recipient, please notify the sender by e-mail and delete the original message. Further, you are not to copy, disclose, or distribute this e-mail or its contents to any other person and any such actions are unlawful. This e-mail may contain viruses. Infosys has taken every reasonable precaution to minimize this risk, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. Infosys reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the Infosys e-mail system. ***INFOSYS******** End of Disclaimer ********INFOSYS*** [Non-text portions of this message have been removed]
