|
You are still talking about the warnings? These warnings are meant to be ignored once you know what they are warning about. I've a piece of code that uses STL Map, and when you compile, the compiler takes minutes to stop it's warning process. Where you should only use the pragma-warning-disable.
He's become a household word in the Lounge. A whole new phraseology has evolved. Post a link or reply with a smiley and rose, and you've made a "Satipsism". So what? It's an interesting thing about the Internet, the evolution (as in change, not progress) of tone, quality, terminology, etc.
-Marc Clifton.
Best wishes to Rexx[^
|
|
|
|
|
Thanks VuNic,
Do you think convert from size_t to unsigned int will cause data lost on 32-bit platform?
regards,
George
|
|
|
|
|
George_George wrote: Do you think convert from size_t to unsigned int will cause data lost on 32-bit platform?
You will loose if you send signed number. Ok, test it by yourself :
<br />
int nIntNeg = -100;<br />
int nIntPos = 100;<br />
size_t sz;<br />
sz=nIntPos;<br />
cout<<"\n"<<sz;<br />
<br />
sz=nIntNeg;<br />
cout<<"\n"<<sz<<endl;<br />
The point here is not about you will/will-not loose data, but it's to say that you wont get into a situation where a function would return signed number for a size_t type.
Eg:
<br />
std::string st;<br />
st="";<br />
cout<<st.size();<br />
At the worst, st's size can me only 0, can't go below that. So you get the point? size_t s are meant for unsigned data. If you send signed numbers, you WILL loose it.
He's become a household word in the Lounge. A whole new phraseology has evolved. Post a link or reply with a smiley and rose, and you've made a "Satipsism". So what? It's an interesting thing about the Internet, the evolution (as in change, not progress) of tone, quality, terminology, etc.
-Marc Clifton.
Best wishes to Rexx[^
|
|
|
|
|
Hi VuNic,
I can understand your points. But I am always using unsigned int. Do you think there will be any data lost if I convert size_t to unsigned int on 32-bit machine?
regards,
George
|
|
|
|
|
|
Hi Roger,
I am using 32-bit only (no 64-bit). I have read the URL from MSDN and there may be warnings when we are using 64-bit platform. But I do not know why in my 32-bit environment, there is still the warning message.
regards,
George
|
|
|
|
|
pragma warning( disable : C4267 )
Did you do this or not?, put that in the afx.h header.
He's become a household word in the Lounge. A whole new phraseology has evolved. Post a link or reply with a smiley and rose, and you've made a "Satipsism". So what? It's an interesting thing about the Internet, the evolution (as in change, not progress) of tone, quality, terminology, etc.
-Marc Clifton.
Best wishes to Rexx[^
|
|
|
|
|
Hi VuNic,
You mean it is a false warning?
regards,
George
|
|
|
|
|
Here[^]
Relatively it's a simple question, wondering it required so much explantion. Think it this way,
Floats are meant for storing percision data, if you store a float value in an int? wont it loose the precision? But you are not going to do that right? the same way unless or otherwise you manually do something like :
<br />
void myFunction(size_t sz)<br />
{<br />
<br />
}<br />
and pass something like
myFunction(-100);
There's no possiblity of loosing data. In short, It looks you aren't sending negative values in your code so please ignore the warning.
He's become a household word in the Lounge. A whole new phraseology has evolved. Post a link or reply with a smiley and rose, and you've made a "Satipsism". So what? It's an interesting thing about the Internet, the evolution (as in change, not progress) of tone, quality, terminology, etc.
-Marc Clifton.
Best wishes to Rexx[^
|
|
|
|
|
Hi VuNic,
I am always using unsigned int as data type. Example,
unsigned int i = <some value="">;
size_t new_value = (size_t)i;
I am not sure whether there will be any data lost if I convert i to new_value as size_t type. I can understand convert to signed int will cause data lost. What about unsigned int?
Looks like we are talking about two different things.
regards,
George
|
|
|
|
|
if your sure you will not go between 32-bit and 64-bit with this code someday then an explicit cast should eliminate the warning. Let the compiler know the conversion is not implicit and it will take your word for it that you know what your doing.
size_t First=45;
int Second=67;
unsigned int Third=98;
// Damned if you do
Second=(int)First;
Third=(unsigned int)First;
// Damned if you don't
Second=static_cast<int>(First);
Third=static_cast<int>(First);
|
|
|
|
|
Hi bob16972,
I am using C and I can not use static_cast template class. I am wondering if I am building application for 32-bit platform only, will there be any data lost if I convert size_t to unsigned int? (not signed int)
regards,
George
|
|
|
|
|
The static_cast was in my post to appease the C++ purists. I use the C-style casts myself.
George_George wrote: I am building application for 32-bit platform only, will there be any data lost if I convert size_t to unsigned int?
No.
Clarification:
I included signed int in my original post without thinking as there is the potential to misinterpret or lose data with that conversion. size_t is supposedly an unsigned int so the conversion from size_t should be pretty clean in a 32-bit only world.
|
|
|
|
|
Hi bob16972,
static_cast is an operator in C++, how do you think we can use it in pure C program?
regards,
George
|
|
|
|
|
Considering this is a C++ forum, I assumed you were using .cpp files. If you are truly using .c files then my apologies. I haven't compiled a "pure" C program since 1992 or 1993.
Either way, I don't use static_cast myself so no harm no foul.
|
|
|
|
|
Thanks bob16972,
It is ok.
regards,
George
|
|
|
|
|
If you don't care about 64-bit compatibility warnings, why not turn the 64-bit compatibility check
off in the compiler settings?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your new idea, Mark!
Do you know how to turn 64-bit compatibility back? Which compiler settings (macros) should I look into?
regards,
George
|
|
|
|
|
I'm still not sure if that's why you're getting the warning. I thought you stated you tried
unsigned int instead of int in an earlier post - if that's the case then it's probably a 64-bit
compatibility warning.
If you go to the project properties, the C++/General page should have the "detect 64-bit portability
issues" switch.
There's also #pragma warning for turning on/off warnings for sections of code.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your advice, Mark!
regards,
George
|
|
|
|
|
size_t in unsigned but int is signed.
Steve
|
|
|
|
|
Hi Stephen,
If I am converting size_t to unsigned int on 32-bit platform, are there any risks of data lost?
regards,
George
|
|
|
|
|
It depends on how the conversion is done. Why not use size_t directly. If you can't perhaps unsigned int would be a closer match.
Steve
|
|
|
|
|
Good idea Steve,
I will try to change the function signature (parameter type).
regards,
George
|
|
|
|
|
Hi all;
I am (new to c++) trying to write a program which in part of it has a list of objects with a few variables.(pseudo code)
lets say:
class cObj
{
private:
int objNum;
string objName;
}
list<cobj> ListObj;
and we have three objects
obj1 ( onjNum =1 , ObjName = One)
obj2 ( onjNum =2 , ObjName = Two)
obj3 ( onjNum =3 , ObjName = Two)
and i want to search all the objects that have the name "Two".
result should be: &Obj2 and &Obj3 (or pointers)
how can i do it?
thanks a lot;
Beri
|
|
|
|