LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] C++ and recursive va_start calls

[ILUG] C++ and recursive va_start calls

Brian Foster blf at utvinternet.ie
Tue Feb 17 01:59:54 GMT 2004


  | 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):

    7.15.1.4  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
    circumstances:
  [ ... ]
      -- 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 (7.15.1.2, 7.15.1.4).

 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!
cheers!
	-blf-
--
«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



More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


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!
RSS Version
Powered by Dell