Reputation: 6305
Here is the problem
I am reviving some old code (pre-ARC, Xcode 4, GDB) in Xcode 5 and while everything compiles and starts fine I have a problem with the output log of the debugger when printing the contents of a C++ string object.
#define DebugPrintf(args...) x_Printf(__FILE__,__LINE__,__PRETTY_FUNCTION__,args);
void x_Printf(const char *file, int lineNumber, const char *funcName, const char *format,...)
{
va_list ap;
va_start (ap, format);
printf("%s (%s:%d)",funcName,file,lineNumber);
printf(format,ap);
va_end (ap);
}
void MyFunc()
{
string name;
…
DebugPrintf("Loaded entity %s\n",name.c_str());
}
Results in:
void MyFunc() (File.cpp:52)Loaded entity \373*
${\370\325\377\277:{\373*
Ģ\247\300\242\247`6*
However inspecting the name C++ string object shows me that it clearly contains "MainMenu" as content.
Anyone knows what's going on?
Upvotes: 0
Views: 730
Reputation: 46598
You should use vprintf
void x_Printf(const char *file, int lineNumber, const char *funcName, const char *format,...)
{
va_list ap;
va_start (ap, format);
printf("%s (%s:%d)",funcName,file,lineNumber);
vprintf(format,ap); // <-- vprintf
va_end (ap);
}
Upvotes: 2