Skip navigation.

Syndicate

Syndicate content

User login

va_start

Why doesn't va_start work with reference parameters?

I’ve been hacking alot of C++ lately as a part of my new job. I implemented a simple string formatting function using __vswprintf_s and the C variable argument constructs va_start, va_list, etc.

I was surprised to discover that, when the prev parameter argument passed to va_start is a C++ reference parameter (like, say, const std::wstring&, as in my case), the resulting variable arguments are garbage, and of course any printf-like function produces nonsense and/or crashes.

It’s not at all clear to me why this is, though it sucks rather profoundly.

Syndicate content