Re: [PATCH/RFC 02/11] strbuf: add non-variadic function strbuf_vaddf()
From: Erik Faye-Lund <hidden>
Date: 2016-06-15 22:47:46
On Thu, Nov 26, 2009 at 7:46 PM, Junio C Hamano [off-list ref] wrote:
Erik Faye-Lund [off-list ref] writes:quoted
In practice it seems that something like the following works portably-enough for many applications, dunno if it's something we'll be happy with: #ifndef va_copy #define va_copy(a,b) ((a) = (b)) #endifSince an obvious implementation of va_list would be to make it a pointer into the stack frame, doing the above would work on many systems. On esoteric systems that needs something different (e.g. where va_list is implemented as a size-1 array of pointers, va_copy(a,b) needs to be an assignment (*(a) = *(b))), people can add compatibility macro later. Historically some systems that do have a suitable implementation had it under the name __va_copy() instead, so it would have been better to define it as something like: #ifndef va_copy # ifdef __va_copy # define va_copy(a,b) __va_copy(a,b) # else # /* fallback for the most obvious implementation of va_list */ # define va_copy(a,b) ((a) = (b)) # endif #endif But I do not know it still matters in practice anymore.
Perhaps I can do one better: use memcpy instead of standard assignment. The Autoconf manual[1] suggests that it's more portable. Something like this: #ifndef va_copy # ifdef __va_copy # define va_copy(a,b) __va_copy(a,b) # else # define va_copy(a,b) memcpy(&a, &b, sizeof (va_list)) # endif #endif I'll add this to git-compat-util.h this for the next round unless someone yells really loud at me. *[1] http://www.gnu.org/software/hello/manual/autoconf/Function-Portability.html#index-g_t_0040code_007bva_005fcopy_007d-357 -- Erik "kusma" Faye-Lund