473,396 Members | 1,784 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,396 software developers and data experts.

va_copy

REH
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.

Nov 14 '05 #1
4 4189
"REH" <me@you.com> writes:
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))


It's not obvious to me why that couldn't be a conforming
implementation of va_copy. However, I wonder whether you really
mean "can I implement it this way?" In general, no: there is no
guarantee that this will have the desired effect.
--
"Your correction is 100% correct and 0% helpful. Well done!"
--Richard Heathfield
Nov 14 '05 #2
>"REH" <me@you.com> writes:
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))

In article <87************@benpfaff.org>
Ben Pfaff <bl*@cs.stanford.edu> wrote:It's not obvious to me why that couldn't be a conforming
implementation of va_copy.
Well, almost:

#define va_copy(dst, src) \
((void) memcpy((dst), (src), sizeof(va_list)))

because C99 says that, while va_copy is a macro, it acts as if it
were a void-valued function.
However, I wonder whether you really mean "can I implement it this
way?" In general, no: there is no guarantee that this will have
the desired effect.


Indeed. In particular, it will not work on implementations in
which "va_list" is a typedef alias for "char *", such as most
Intel-x86 systems.

There is always some way to define va_copy() that will work, but
the actual definition needs to change from one platform to the next.
The two most common definitions are the memcpy above, and the
even simpler:

#define va_copy(dst, src) ((void)((dst) = (src)))

Without knowing how the compiler implements va_list, va_start, etc.,
it is impossible to tell which of these two common definitions will
work (or whether a different, uncommon, definition is required).
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #3
> >"REH" <me@you.com> writes:
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))
Ben Pfaff <bl*@cs.stanford.edu> wrote:
It's not obvious to me why that couldn't be a conforming
implementation of va_copy.

Chris Torek wrote: Well, almost:

#define va_copy(dst, src) \
((void) memcpy((dst), (src), sizeof(va_list)))

because C99 says that, while va_copy is a macro, it acts as if it
were a void-valued function.


How would a strictly conforming program tell the difference?

--
Peter

Nov 14 '05 #4
>Chris Torek wrote:
[I inserted a (void) cast in a memcpy()]
... C99 says that, while va_copy is a macro, it acts as if it
were a void-valued function.

In article <11**********************@o13g2000cwo.googlegroups .com>
Peter Nilsson <ai***@acay.com.au> wrote:How would a strictly conforming program tell the difference?


This is a bit of an odd situation, really.

Without the cast, you could feed an "invalid" translation unit --
one that requires a diagnostic, that is -- to a compiler and perhaps
get no diagnostic:

void vfunc(const char *fmt, ...) {
va_list va1, va2;

va_start(fmt, va1);

void *p = va_copy(va1, va2);
/* more code here */
}

But a compiler is always free to emit bogus diagnostics, so even
if we remove the "void *p =" part, we could still get a diagnostic.

This means there is no *guaranteed* way to discover that va_copy()
is mis-#defined, and we cannot write a strictly conforming program
to find out.

Still, whenever we (C programmers) play the role of "implementor",
writing some or all of a C compiler, we should at least strive to
give useful diagnostics. Defining va_copy without the (void) cast
will usually omit the useful diagnostic, and -- depending on the
compiler -- might even omit the required one.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #5

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

Similar topics

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?
4
by: Johan Lindh | last post by:
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...
4
by: Old Wolf | last post by:
#include <stdio.h> #include <stdarg.h> Is this safe: void foo(const char *fmt, ...) { va_list ap; va_start(ap,fmt);
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...
9
by: grid | last post by:
Hi, I have a function which takes a variable number of arguments.It then calls va_start macro to initialize the argument list.But here in my case I have a special builtin va_start provided by the...
2
by: Laurent Deniau | last post by:
Is the following code valid: void func(int va_flag, ...) { va_list va; va_start(va, va_flag); if (va_flag) { // indirect va_list va_copy(va, va_arg(va, va_list)); }
4
by: saumya.agarwal | last post by:
Hi, I am executing a piece of code which continually tries to do the sprintf into the allocated buffer on a 64-bit RedHat linux machine. Here are the details of the system and the gcc version...
1
by: braj | last post by:
Hi Friends, I was trying a test code to use the icu stuff with variable arguments and I seem to be heading nowhere. Can anyone please help. Given below is the test code and the Output. ...
9
by: tonybalinski | last post by:
I'd like to be able to scan a va_list twice in a v... function, but can't see how to do it. For example char *strdupcat(const char *first, ...) { char *result, pos; va_list arg; size_t len;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.