Doh! You're right. The format string must be the right type, but any
additional arguments are untyped.
'scuse me.
"Jonathan Wood" <jwood@softcircuits.com> wrote in message
news:eXWDyj1HJHA.2580@TK2MSFTNGP05.phx.gbl...
A cast to LPCTSTR in an argument to printf() in a Unicode build, should
cause a warning/error. In a Unicode build, LPCTSTR is LPCWSTR and
printf() expects LPCSTR.
That's what I originally thought, but with var args the compiler doesn't
give a warning even at level 4.
Here's my test code for this thread:
//
// Tested on Visual Studio 2008 SP1
//
CString kindOfFruit = _T("bananas");
int howmany = 25;
char buff[80];
sprintf(buff, "You have %d %s", howmany, CT2A(kindOfFruit) );
sprintf(buff, "You have %d %s", howmany, (LPCTSTR)kindOfFruit );
sprintf(buff, "You have %d %s", howmany,
static_cast<LPCTSTR>(kindOfFruit));
No warnings (except the deprecated functions).
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++