Re: vsprintf in std
Jack wrote:
The entire function looks like
void appendStrTab (strTable *strTab, char *format, ...)
/* Appends the new line (in printf style) to the string table strTab. */
{ va_list args;
va_start (args, format);
if (strTab->numLines == strTab->allocLines)
{
incTableSize (strTab);
}
strTab->str[strTab->numLines] = (char *)malloc(lineSize * sizeof(char));
if (strTab->str == NULL)
{
fatalError(MALLOC_FAILED, lineSize * sizeof(char));
}
vsprintf (strTab->str[strTab->numLines], format, args);
strTab->numLines++;
va_end (args);
}
You see that most of the statements of this function is unmanaged.
I prefer using std to crt, so I want to alter this program (open-source) in
my own style
The CRT is part of std. You can change the above just by using:
#include <cstdio>
#include <cstring>
#include <cstdlib>
///...
void appendStrTab (strTable *strTab, char *format, ...)
/* Appends the new line (in printf style) to the string table strTab. */
{ va_list args;
va_start (args, format);
if (strTab->numLines == strTab->allocLines)
{
incTableSize (strTab);
}
strTab->str[strTab->numLines] = (char *)std::malloc(lineSize *
sizeof(char));
if (strTab->str == NULL)
{
fatalError(MALLOC_FAILED, lineSize * sizeof(char));
}
//see std:: used below!
std::vsprintf (strTab->str[strTab->numLines], format, args);
strTab->numLines++;
va_end (args);
}
Or do you mean you want to rewrite the C function using idiomatic C++
style (e.g. with std::string, etc.)? If so, can you change the signature
of the function? Can you change the strTable type?
Tom