variadic functions - C++ - va_list Bad Pointer -
i getting exception of bad pointer (0xcccccccc ) temp below under case 's':
string logger::format(const char *str, va_list args) { ostringstream output; for(int = 0; < strlen(str); ++i) { if(str[i] == '%' && str[i+1] != '%' && i+1 < strlen(str)) { switch(str[i+1]) { case 's': { char *temp = va_arg(args, char*); output << temp; break; } case 'i': { int temp = va_arg(args, int); output << temp; break; } case 'd': { double temp = va_arg(args, double); output << temp; break; } case 'f': { float temp = va_arg(args, float); output << temp; break; } default: output << str[i]; } i++; } else { output << str[i]; } } return output.str(); }
the above function called this:
void logger::debugformat(string message, ...) { const char* cstr = message.c_str(); va_list args; va_start(args, cstr); record(debugging, format(cstr, args)); va_end(args); }
i calling above way in code
logger::debugformat("loading image %s", path.c_str());
any other type (int, double, float) work fine. appreciated.
you aren't using va_start
properly. second argument supposed function parameter after variable list of arguments (represented ...
) starts. is, should be:
va_start(args, message);
Comments
Post a Comment