Reputation: 5635
I know how to call vprintf, etc from an implementation of printf, correspondingly.
But what if I want to create an argument list dynamically in code, especially for vsscanf
, where I know they are all pointers?
Is there some reasonably portable way that I can convert my dynamically allocated and filled array of pointers (actually a std::vector) into a va_list?
This is all so that I can add a %n argument to the end and detect how much input was actually consumed, in order to provide an answer to ftell in my own FILE-like wrapper.
Other than doing something hairy with a pipe; or writing my own implementation; or splitting the string and doing one argument at a time; I don't see how else I can detect the input stream usage, especially for sscanf. So other ideas to that end might be interesting.
Upvotes: 1
Views: 141
Reputation: 5635
X-Y answer: In the end I used fopencookie and vfscanf on that, so I didn't have to process the arguments nor process the format string.
Upvotes: 0
Reputation: 239
Argument lists, be they fixed or variable sized, are static compile-time entities. So in runtime you can read them, but not create. Use conventional pointers instead.
The sole purpose of va_list
is an iteration through arguments because nothing else provides durable access to them. So treat it as a roundabout for a specific feature of a language (a possibility to pass more arguments than specified in a prototype), not intended to be used anywhere else.
Upvotes: 1