Printf problem


#1

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?


#2

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


#3

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


#4

Try casting to a const tchar*


#5

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


#6

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:


#7

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.


#8

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


#9