Printf problem

I have something like

DBG_PRINTF( (T(“My format string %S”), myString.toUTF8()) );

That works fine on PC, but gets stuck in an infinite loop in String::vprintf (const tchar* const pf, va_list& args), as the buffer never seems to be big enough.

Now if you try to do this with %s instead of %S, it works on Mac but writes out crazy things on PC.

Any idea how to make it work on both platforms?

Looks like you’re mixing up character sets - why are you turning it into utf8 when it’s a unicode function call?

I used utf8 because the String type won’t work with the built system functions. Should I just cast it to something?

Try casting to a const tchar*

That was my idea too, but although casting to const tchar* works on Mac, it prints only the first character on PC. Weird!

OK

DBG_PRINTF( (T(“My format string %s”), (const tchar*) myString) );

(with lowercase %s) seems to do the trick on both platforms. Man, I hate this string stuff :slight_smile:

So the PC must be expecting a non-unicode string. Strange, because I do use the wide-character version of vprintf… Sorry, can’t think of a good workaround except casting it to different things on different platforms.

And reasons like that I like to use boost::format instead of any sprintf type function…