jeudi 5 mars 2020

is it safe to use va_copy on windows

I have gone through the link https://devblogs.microsoft.com/oldnewthing/20131114-00/?p=2663 for potential pitsfalls using va_list

And below code segment from the same link specifies not to use va_list in manner shown because a va_list is not directly copyable.

BOOL FormatWithFallbackLanguage(
    DWORD dwMessageId, PCTSTR pszBuffer, SIZE_T cchBuffer, va_list ap)
{
 va_list apOriginal = ap;
 // Format from the user's preferred language.
 DWORD cchResult = FormatMessage(
               FORMAT_MESSAGE_FROM_HMODULE,
               g_hinst, dwMessageId, g_preferredLangId,
               pszBuffer, cchBuffer, &ap);
 // If that didn't work, then use the fallback language.
 if (cchResult == 0) {
  cchResult = FormatMessage(
               FORMAT_MESSAGE_FROM_HMODULE,
               g_hinst, dwMessageId, g_fallbackLangId,
               pszBuffer, cchBuffer, &apOriginal);
 }
 return cchResult != 0;
}

The article in the link suggesting to use va_copy for above coding scenario. However on windows, in the header file stdarg.h , the va_copy doesn't seem to be doing anything

#define va_copy(destination, source) ((destination) = (source))

My question is that whether its safe to use va_copy in windows for va_list ? If yes, why and if not then whats the way forward?

Aucun commentaire:

Enregistrer un commentaire