Click here to Skip to main content
16,020,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I compiled a legacy project in Visual Studio 6.0 and got this warning:

Warning	C4840	non-portable use of class 'ATL::CStringT<char,StrTraitMFC<char,ATL::ChTraitsCRT<_CharType>>>' as an argument to a variadic function


I know it is related with static_cast<>, how can I fix this warning?

What I have tried:

I tried to use static_cast<>(), but what is the target type to convert? ATL::CStringT?
Posted
Updated 24-Dec-20 11:08am
Comments
Greg Utas 24-Dec-20 13:32pm    
What is the line of code that causes this warning, and what is the signature of the variadic function that it's calling?

1. Find the line that is causing the error. The full error message should contain that info.
2. That line contains some kind of function calls that is able to deal with different types of input, e. g. a template function, or maybe a function of the printf() family.
3. In that function call, analyze what, exactly should be the argument types in this paticular case.
4. Check if the arguments passed are actually the ones that you meant to pass, not e. g. a pointer to the actual object, or a struct containing the object.
5. It may well be that a static_cast (as suggested) would eliminate the error, but chances are that your are not passing the right argument, and that you should fix that - or else you'll be stuck with a rather hard to locate run time error!

Or simply post the actual code here and we can perform these steps for you...

P.S.:
Quote:
I know it is related with static_cast<>

Most certainly not! If anything, static_cast tends to obscures errors, not introduce new ones. However, it's impossible to say in this case as long as you don't show the code.
Quote:
what is the target type to convert? ATL::CStringT?

The error message doesn't say. And we can't say either, because you haven't provided the code. But, obviously, ATL:CStringT is what the type currently is, and it is wrong. So, no, that is the one type that we can say for sure that you shouldn't convert it to!
 
Share this answer
 
v2
When I have seen this it happened with a line of code like :
C++
printf( "this is a string : %s\n", stringObject );
The target type of the conversion should be const TCHAR * which has a definition of PCTSTR.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900