473,324 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Correct use of va_copy

Hi all,

If I read the standard correctly, a va_list variable
that's initialized using va_copy() should be terminated
with a va_end() on it. Is this correct?

int test( va_list x )
{
va_list x_copy;

va_copy( x_copy, x );
va_end( x_copy );

return 0;
}
Regards,

Johan
Nov 14 '05 #1
4 11156
Johan Lindh wrote:
If I read the standard correctly, a va_list variable
that's initialized using va_copy() should be terminated
with a va_end() on it. Is this correct?


Yes. Note that the relevant text has changed between n869 and C99.

Jeremy.
Nov 14 '05 #2
Jeremy Yallop wrote:
Johan Lindh wrote:
If I read the standard correctly, a va_list variable
that's initialized using va_copy() should be terminated
with a va_end() on it. Is this correct?

Yes. Note that the relevant text has changed between n869 and C99.


I only have the C99; if it's needful to know the n869 (whatever THAT
is... =), please post it.

Nov 14 '05 #3
Johan Lindh <jo***@linkdata.getridofthis.se> wrote:
Jeremy Yallop wrote:
Johan Lindh wrote:
If I read the standard correctly, a va_list variable
that's initialized using va_copy() should be terminated
with a va_end() on it. Is this correct?

Yes. Note that the relevant text has changed between n869 and C99.


I only have the C99; if it's needful to know the n869 (whatever THAT
is... =), please post it.


N869 is the last public draft of the ISO/IEC 9899:1999 standard
and is available at:
http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/.
n869 7.15.1.3 (The va_end macro):
[...]
[#2] The va_end macro facilitates a normal return from the
function whose variable argument list was referred to by
the expansion of va_start that initialized the va_list ap.
The va_end macro may modify ap so that it is no longer
usable (without an intervening invocation of va_start).
If there is no corresponding invocation of the va_start
macro, or if the va_end macro is not invoked before
the return, the behavior is undefined.

ISO/IEC 9899:1999(E) 7.15.1.3 (The va_end macro):
[...]
2 The va_end macro facilitates a normal return from the function
whose variable argument list was referred to by the expansion
of the va_start macro, or the function containing the expansion
of the va_copy macro, that initialized the va_list ap. The
va_end macro may modify ap so that it is no longer usable
(without being reinitialized by the va_start or va_copy macro).
If there is no corresponding invocation of the va_start or
va_copy macro, or if the va_end macro is not invoked before the
return, the behavior is undefined.

HTH
Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc : http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.eskimo.com/~scs/C-faq/top.html
acllc-c++ faq : http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

Nov 14 '05 #4
Irrwahn Grausewitz wrote:
Johan Lindh <jo***@linkdata.getridofthis.se> wrote:
Jeremy Yallop wrote:
Johan Lindh wrote:

If I read the standard correctly, a va_list variable
that's initialized using va_copy() should be terminated
with a va_end() on it. Is this correct?
Yes. Note that the relevant text has changed between n869 and C99.
I only have the C99; if it's needful to know the n869 (whatever THAT
is... =), please post it.


It's not needful. n869 is an obsolete draft of the standard. I only
mentioned it seems to be fairly widely used here, and it gives
misleading information in this case.
n869 7.15.1.3 (The va_end macro): [...] ISO/IEC 9899:1999(E) 7.15.1.3 (The va_end macro):

[...]

FWIW, I was referring to 7.15.1, specifically

Each invocation of the va_start and va_copy macros shall be matched
by a corresponding invocation of the va_end macro in the same
function.

n869 says:

Each invocation of the va_start or va_copy macros shall be matched
by a corresponding invocation of the va_end macro in the function
accepting a varying number of arguments.

which is wrong, particularly with respect to the OP's code, where
va_copy was invoked in a function that accepted a single argument.

Jeremy.
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: David Opstad | last post by:
I have a question about text rendering I'm hoping someone here can answer. Is there a way of doing linguistically correct rendering of Unicode strings in Python? In simple cases like Latin or...
0
by: Sarah Tegtmeier | last post by:
Hi I have a question about the correct use of the attribute xsi:schemaLocation. My programm has to process XML files where the value of this attribute causes some problems. The programm is...
1
by: Richard Golebiowski | last post by:
I have been trying to figure this out for quite some time and cannot find any examples in VB.Net or in VB that work correctly. I am working on an application where I want the user to be able to...
3
by: Servé Lau | last post by:
What would be a good implementation of va_copy where va_list is a typedef for char *? Can I jyust copy the pointer's value or is it impossible to tell without knowing more details?
1
by: Ian Pilcher | last post by:
Can va_copy be used to copy a va_list object that was initialized in a different function? (I.e. the function in which va_copy is used is called by the function in which the original va_list is...
4
by: REH | last post by:
Is there a standard when to implement va_copy in the pre-99 standard? Is this allowed by the standard: #define va_copy(DEST, SRC) memcpy((DEST), (SRC), sizeof(va_list)) Thanks.
2
by: thisis | last post by:
Hi All, I need the PUBS.mdb for pulling images: PUBS.mdb must have the table: pub_info tbl_pub_info : has 3 fields Data_Type : ok Data_Type : ok
3
lee123
by: lee123 | last post by:
I have a problem getting the correct to count +1 every time I get an answer right and the incorrect is the same. I have two lbl's named number1 and number2 which produces a Rnd# in each lbl. ...
10
by: onetruelove | last post by:
I want to creat a post like this blog: http://onlinetoefltest.blogspot.com/2007/08/level-c-lesson-1.html When you chose all the answers and click show answer a msg box will appear and tells how...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.