MSDN shows this example code snippet for vsnprintf_s :
// crt_vsnprintf_s.cpp #include <stdio.h> #include <wtypes.h> void FormatOutput(LPCSTR formatstring, ...) { int nSize = 0; char buff[10]; memset(buff, 0, sizeof(buff)); va_list args; va_start(args, formatstring); nSize = vsnprintf_s( buff, _countof(buff), _TRUNCATE, formatstring, args); printf("nSize: %d, buff: %s\n", nSize, buff); } int main() { FormatOutput("%s %s", "Hi", "there"); FormatOutput("%s %s", "Hi", "there!"); FormatOutput("%s %s", "Hi", "there!!"); }
In this example, va_start is called without va_end matching.
Is this a document error on MSDN, or are we just calling va_start before calling vsnprintf_s , and then let this function do the cleanup (i.e. calling va_end ) for us?
BTW: I tried the above code and it works with VS2015 with Update 3, but I don't know if this behavior is just undefined ...
c ++ c variadic-functions
Mr.C64
source share