This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: va_list and x86_64 possible bug (?)
On 10/17/07, Macy Gasp <macygasp@gmail.com> wrote:
> On 10/17/07, Andrew Haley <aph-gcc@littlepinkcloud.com> wrote:
> > Macy Gasp writes:
> > > Hi everybody,
> >
> > Read the Fine Manual:
> >
> >
> > int vsprintf(char *str, const char *format, va_list ap);
> >
> > The functions vprintf(), vfprintf(), vsprintf(), vsnprintf()
> > are equivalent to the functions printf(), fprintf(), sprintf(),
> > snprintf(), respectively, except that they are called with a
> > va_list instead of a variable number of arguments. These
> > functions do not call the va_end macro. C onsequently, the value
> > of ap is undefined after the call. The application should call
> > va_end(ap) itself afterwards.
> >
> >
> > Andrew.
> >
>
> Thanks for the answer, I missed that part :( .
> Thanks to the other Andrew too , for his answer :)
>
By the way, I need a suggestion... I want to write a "format_string"
function in C++, like this:
std::string format_string(const char* format, va_list args);
This has an internal static buffer in which I try 1st to vsnprintf().
If it overflows, I dynamically allocate a suitable buffer and try
vsnprintf again.
The problem is that I'd need to va_copy the args variable in order to
re-use it for the second vsnprintf; but this isn't portable on Windows
using cl (probably other platforms too)...
Any ideas on how I could solve this?