Why Can't we use va_list twice?
Can any explain me how it creates memory issue ?

Quoting from man stdarg:

Multiple traversals of the list, each bracketed by va_start() and va_end() are possible.

So yes, you can use a va_list twice.

You can use a va_list twice, provided it's properly disposed of with va_end() and re-initialized with va_start() or copied with va_copy(). What you can't do is assume that va_list represents a bidirectional read-only collection. It could easily be a generated array or list of arguments that are modified or destroyed after processing with va_arg.

commented: nice one!! +2

Question Rephrased...
Why Can't we use same va_list twice?

Answer rephrased: You can use the same va_list twice.

If you mean why can't you use the same va_list twice without resetting it with va_end and va_start: How would that work? You have to rewind it somehow - otherwise how could it possibly know that you want to start from the beginning and not just read more arguments?

commented: hehe :p +2

hmm...

firstly procedure is :

va_list ap;
va_start(fmt,ap);
then you can extract the variable agruments one by one using the va_arg(ap,type)

. simple!

If, you want to use va_list again for the same variable arguments, then end it first. how ? using va_end(ap); . now what ? now again repeat my procedure which i have given above. that's set. thanks. :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.