Avatar of _Stilgar_
_Stilgar_Flag for Israel asked on

Detecing an empty va_list?

Hi all,

I have a function that accepts an LPCTSTR. I want to add functionality to parameterized strings - that is, to have the LPCTSTR go through _vsntprint - but since it requires copying the string to a buffer, or making the current buffer larger, I want to call it only if the parameters list is not empty. I would want to use the same function I do now, without creating another version of it which accepts an ellipsis.

So, if my function looks like this: int Execute (LPCTSTR command) , I want it to look like this: int Execute (LPCTSTR command, ...). I'm then using va_start, but couldn't figure out how to see if it points to an empty parameters list or not. I'm not even sure using va_arg is possible for testing this (of course I will have to do va_list args-- after calling it). Passing an int with parameters count is not an option.

Any advice on how to do this (if at all possible)?

Editors IDEsCC++

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Your function could analyze the command string and see if it calls for additional parameters.  If it does, the function could then assume that the additional parameters were passed and allocate the memory for the copy.

This is not an answer to the specific question of how to tell if optional parameters were passed.  It's rather a suggestion for solving the larger problem.

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.