va_start and references

J

John Harrison

Is the following code OK?

#include <stdarg.h>

void func(const X& x)
{
va_list args;
va_start(args, x);
funcv(x, args);
va_end(args);
}

void funcv(const X& x, va_list args)
{
// ...
}

In other words is it OK to use va_start on an parameter that is a reference?
I can't see anything that says it isn't, nor can I see why it shouldn't work
from looking at the definition of va_start in my compiler (VC++ 7). But I
get memory access errors in funcv, which only go away when I change the type
of the parameter to func from const X& to X.

john
 
R

red floyd

John said:
OK thanks, I'd of found that reference if va_start had been in the index of
the standard.

john


Also, try using <cstdarg> instead of <stdarg.h>
 
R

red floyd

It was my impression that the <XXX.h> C90 headers were deprecated in
favor of the <cXXX> headers in C++98.
 
R

Ron Natalie

red floyd said:
It was my impression that the <XXX.h> C90 headers were deprecated in
favor of the <cXXX> headers in C++98.

Deprecation has no real meaning however.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top