I'm using VS2010 Pro compiler, when I build on x64 I get below compilation error. Compiles perfectly on x86. error C2704: '' : __va_start intrinsic only allowed in varargs
Declaration of method:
int foo(char* buf, int maxChar, const char*& fmt);
definition:
int foo(char* buf, int maxChar, const char*& fmt)
{
int numChar = 0;
if (fmt)
{
va_list plist;
va_start(plist, fmt);
numChar = _vsnprintf(buf, maxChar, fmt, plist);
va_end(plist);
}
return numChar;
}
What is the meaning of the error? How to fix this?
I think it means pretty much what it says. The compiler won't allow you to use va_start
, va_arg
, etc, except in a variable argument function. Using va_start
outside of a vararg function makes no sense.
This doesn't define a variable argument function:
int foo(char* buf, int maxChar, const char*& fmt)
This does:
int foo(char* buf, int maxChar, const char*& fmt, ...)
On x86, all arguments are passed on the stack, and it's semantically safe (albeit incorrect) to use va_start
and friends to get "arguments".
However, on amd64 (and most likely on ARM), some arguments are passed via registers. In this case, using va_start
in a function that isn't declared to take variable arguments is semantically unsafe - va_start
would index into invalid memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With