| From: Vincent Cunniffe <vincent at cunniffe.net>
| Date: Mon, 16 Feb 2004 22:28:28 +0000
| anyone had any experience with this? I have a situation
| where a function with a va_start call in it is being called
| from inside another va_start, and it's corrupting the hell
| out of the arguments.
| If I perform exactly the same operation, but in sequence,
| it works fine, but it's a lot less elegant. I can't find
| any mention of it being illegal.
I am assuming here both va_start()s are using
the _same_ va_list: that is 100% illegal in C,
and I know of no reason for C++ to be different.
from the ISO C99 standard (C89 is very similar):
22.214.171.124 The va_start macro
[ ...(N.b. `ap' is a va_list object) ]
[#3] The va_start macro initializes ap for subsequent use by
va_arg and va_end. va_start (or va_copy) shall not be
invoked again for the same ap without an intervening
invocation of va_end for the same ap.
[ ... ]
J.2 Undefined behavior
[#1] The behavior is undefined in the following
[ ... ]
-- The va_copy or va_start macro is called to initialize a
va_list that was previously initialized by either macro
without an intervening invocation of the va_end macro
for the same va_list (126.96.36.199, 188.8.131.52).
if you are using GNU gcc(1), or a C99-conformant
compiler, you should be able to use va_copy() to
duplicate the va_list (_before_ the first va_start()),
and then va_start() the copy when needed.
hope this helps!
«How many surrealists does it take to | Brian Foster Montpellier,
change a lightbulb? Three. One calms | blf at utvinternet.ie France
the warthog, and two fill the bathtub | Stop E$$o (ExxonMobile)!
with brightly-colored machine tools.» | http://www.stopesso.com
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!