Platform independent DBG_PRINTF

I’m going mad. Is there a way to do x-platform debug printing of String ? On one hand, in Windows I must use %s and (const juce_wchar*) cast, whilst on Mac I must use %S for the same thing. Any suggestions?

Edit: If I for JUCE_WIN32 change CharacterFunctions::vprintf to have the same implementation as for MACOS_10_3_OR_EARLIER, it works fine. That is %s is associated with single-byte character strings and %S is associated with wide-char strings.

Question: Will this break anything? If not, I’d suggest the change for juce.

Hmm - I’m surprised that the mac version would work properly on win32, because it’s casting a wchar* to a char*, and using it as the format string. Not sure about this really…

Ah, but the char* cast of dest is just used internally to render the buffer via vprintf, then it is converted back to juce_wchar*. And formatTemp is converted to const char* correctly by the String class. That’s why it works…

What about a :

#ifdef WIN32
   #define S "%s"
#else
   #define S "%S"
#endif

...printf ("The " S " cat is "S"\n", T("blue"), T("dead")); 

BTW, if you compile in non unicode, then using “%S” everywhere will break, while the macro can still be adjusted.

Printf is too limited anyway.

[quote=“X-Ryl669”]What about a :

[code]
#ifdef WIN32
#define S “%s”
#else
#define S “%S”
#endif

…printf (“The " S " cat is “S”\n”, T(“blue”), T(“dead”));
[/code][/quote]

Shrug… :? …

If I compile in non-unicode then I guess the int CharacterFunctions::vprintf (char* const dest …) variant is used which solves that problem, I think…

You might be right.
I haven’t dealt with the implementation.

Anyway, FYI: typesafe text formatting

A very nice read, thanks! Jules, might be sumthin’ to include in juce, eh? :slight_smile:

I just get a broken link when I try to look at that page…

It’s a PDF about a typesafe based Printf implementation.
I can send you the PDF if you want.

Note that GCC automatically checks printf(…) va args, but it’s not required in standard.
VS up to 2k5 doesn’t. Oh, and printf is deprecated, you have to use “Whatsthat” secure_printf instead.