← Back to team overview

dolfin team mailing list archive

Re: vsnprintf alternative

 

Quoting Anders Logg <logg@xxxxxxxxx>:

> On Sat, Jun 16, 2007 at 12:00:01AM +0200, Garth N. Wells wrote:
> 
> > Is there a C++ alternative to using the function "vsnprintf" (it's used on
> > log.cpp and XMLFile.cpp and perhaps elsewhere). The problem is that it
> gives a
> > compile error under Cygwin. Quite a while ago a replaced "snprintf" with
> some
> > std::string functions to avoid this problem.
> > 
> > Garth
> 
> The only place where this is strictly needed is in log.cpp where one
> needs to handle a variable number of arguments.
> 
> There are a few possible solutions:
> 
> 1. Does changing the include from <stdarg.h> to <stdarg> help?
> stdarg.h is deprecated for C++ so this should be done anyway.
>

No.
 
> 2. Does vsprintf() work as an alternative to vsnprintf()? 

Yes.

The
> difference is that for vsnprintf() one can set a limit for the size of
> the buffer used (but we can get around this by manually checking the
> string length).
>

vsnprintf() is not part of the ansi standard, so using the compiler option
"-ansi" leads to the error with Cygwin.

In the past, I replaced snprintf() using std::ostringstream and std::string to
avoid this problem. I can change the compile flags to avoid the error for now.

Garth


 
> /Anders
> _______________________________________________
> DOLFIN-dev mailing list
> DOLFIN-dev@xxxxxxxxxx
> http://www.fenics.org/mailman/listinfo/dolfin-dev
> 


Follow ups